coderz.py

Keep Coding Keep Cheering!

Generate Parenthesis | Intuition + Code | Recursion Tree | Backtracking | Java

Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1: Input: n = 3 Output: [“((()))”,”(()())”,”(())()”,”()(())”,”()()()”]Example 2: Input: n = 1 Output: [“()”] Solution: This problem can be solved using the concept of backtracking, Let’s see how to approach it. We have to write a function generate([], left, right, […]

September 24, 2024 | 23 DSA Patterns | No comments

Square Root of Integer

Given an integer A. Compute and return the square root of A. If A is not a perfect square, return floor(sqrt(A)). The value of A can cross the range of Integer.

August 10, 2023 | DSA Sheet | No comments

Build Array From Permutation

Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it. A zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive).

August 9, 2023 | DSA Sheet | No comments

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is commonly used to implement priority queues and efficient sorting algorithms like heap sort.

June 10, 2023 | Algorithm, Data Structure | No comments

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is a tree-like data structure used for fast string searching and prefix matching. It allows for the quick retrieval of words or keys connected with each node. The word Trie is derived from reTRIEval, which means finding something or obtaining it.  […]

May 31, 2023 | Data Structure | No comments

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of two nodes, n1 and n2, is the shared ancestor located farthest from the root and has both n1 and n2 as descendants. Properties of the Lowest Common Ancestor: An LCA can be one of the input nodes themselves if one […]

May 30, 2023 | Data Structure | No comments

Binary Search Tree (BST)

A Binary Search Tree (BST) is a type of binary tree that satisfies the following properties: For any node in the tree, all values in its left subtree are less than its value. For any node in the tree, all values in its right subtree are greater than its value. The left and right subtrees […]

May 29, 2023 | Data Structure | No comments

Types of Views & Binary Trees

In binary trees, the views and types refer to different perspectives and classifications of the tree structure. Types of Views in Binary Tree are : Horizontal View: The horizontal view of a binary tree shows the nodes from left to right at each level. Nodes at the same level are listed in the order of their […]

May 29, 2023 | Data Structure | No comments

Binary Trees: Structure & Tree travels

Binary Tree Structure: A binary tree is a tree data structure where each node has at most two children: a left child and a right child. The topmost node of a binary tree is called the root node. Each node in a binary tree can have either zero, one, or two child nodes. The child […]

May 28, 2023 | Data Structure | No comments

Queues in DSA

What is a Queue in DSA? A queue is a linear data structure that holds elements in a certain order. It accesses items using the FIFO (First In First Out) method. It can only be changed by adding data entities at one end or removing data entities at the other. The end where insertion occurs is known as the Rear, while the end where deletion occurs is known as the Front. This ordering guarantees that components are processed […]

May 26, 2023 | Data Structure | No comments

Advertisement