Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 159 of 377

Longest Increasing Subsequence in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 3K+ Views

Suppose we have an unsorted list of integers. We have to find the longest increasing subsequence. So if the input is [10, 9, 2, 5, 3, 7, 101, 18], then the output will be 4, as the increasing subsequence is [2, 3, 7, 101]To solve this, we will follow these steps −trail := an array of length 0 to length of nums – 1, and fill this with 0size := 0for x in numsi := 0, j := sizewhile i is not jmid := i + (j - i) / 2if trails[mid] < x, then i := mid + 1, ...

Read More

Matrix Block Sum in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 509 Views

Suppose we have one m * n matrix called mat and an integer K, we have to find another matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for i - K

Read More

Find the City With the Smallest Number of Neighbors at a Threshold Distance in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 579 Views

Suppose there are n cities numbered from 0 to n-1. If we have the array edges where edges[i] = [fromi, toi, weighti] represents a bidirectional and weighted edge between cities fromi and toi, and given the integer distance threshold. We have to find the city with the smallest number of cities that are reachable through some path and whose distance is at most distance threshold, If there are more than one such cities, return the city with the greatest number.So if the input is like −n is 4 and the distance threshold is also 4, then the output will be ...

Read More

Find K Pairs with Smallest Sums in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 275 Views

Suppose we have two sorted arrays A1 and A2, and another value k. We have to define a pair (u, v) which is consists of one element from A1 and another element from A2. We have to find the k pairs like [(u1, v1), (u2, v2), …, (uk, vk)]. So if A1 = [1, 7, 11] and A2 = [2, 4, 6], and k = 3, then output will be [(1, 2), (1, 4), (1, 6)]To solve this, we will follow these steps −Define one data type, that will take two values a and b, and index.create one priority queue, ...

Read More

Sum of Nodes with Even-Valued Grandparent in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 239 Views

Suppose we have a binary tree, we have to find the sum of values of nodes with even-valued grandparent. (A grandparent of a node is the parent of its parent, if it exists.). If there are no such nodes with an even-valued grandparent, then return 0. So if the tree is like −The output will be 18. The red nodes are nodes with even-value grandparent, while the blue nodes are the even valued grandparents.To solve this, we will follow these steps −Define a map called parentDefine a method called solve(), this will take node and parif node is null, then ...

Read More

Odd Even Linked List in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 765 Views

Suppose we have a singly linked list, we have to group all odd nodes together followed by the even nodes. Here we are talking about the node position not the value in the nodes. We should try to do it in place. So if the nodes are [1, 22, 13, 14, 25], the result will be [1, 13, 25, 22, 14]To solve this, we will follow these steps −if head is null or the next of head is null, then return headhead1 := head, head2 := next of head, head_beg := next of headwhile next of head2 is nor null ...

Read More

Minimum Flips to Make a OR b Equal to c in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 721 Views

Suppose we have 3 positives numbers a, b and c. We have to find the minimum flips required in some bits of a and b to make (a OR b == c ). Here we are considering bitwise OR operation.The flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation. So if a : 0010 and b := 0110, so c is 0101, After flips, a will be 0001, and b will be 0100To solve this, we will follow these steps −ans := 0for i in range 0 ...

Read More

Kth Smallest Element in a Sorted Matrix in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 503 Views

Suppose we have a n x n matrix where each of the rows and columns are sorted in increasing order, we have to find the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not the kth unique element. So if the input is like [[1, 5, 9], [10, 11, 13], [12, 13, 15]], if k = 8, then the output will be 13.To solve this, we will follow these steps −define one method called checkVal() and the arguments are matrix and valuei := 0, j := length of matrix[0] – ...

Read More

Increasing Triplet Subsequence in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 655 Views

Suppose there is an unsorted array. We have to check whether an increasing subsequence of length 3 exists or not in that array.Formally the function should −Return true if there exists i, j, ksuch that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return false.To solve this, we will follow these steps −small := infinity, big := infinityfor each element i in arrayif i

Read More

Reduce Array Size to The Half in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have an array arr. We can choose a set of integers and remove all the occurrences of these integers in the array. We have to find the minimum size of the set so that at least half of the integers of the array are removed. So for example, if arr = [3, 3, 3, 3, 5, 5, 5, 2, 2, 7], then the output will be 2. This is because if we choose {3, 7} this will make the new array [5, 5, 5, 2, 2] which has size 5 (this is equal to half of the size ...

Read More
Showing 1581–1590 of 3,768 articles
« Prev 1 157 158 159 160 161 377 Next »
Advertisements