Arnab Chakraborty has Published 4293 Articles

Next Permutation in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 05:42:40

4K+ Views

Suppose we want to implement the next permutation method, that method rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, this method will rearrange it as the lowest possible order (That is actually, sorted in ascending order). The replacement must be in-place and ... Read More

Random Pick with Weight in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 13:41:58

1K+ Views

Suppose we have an array w of positive integers, were w[i] describes the weight of index i, we have to define a function pickIndex() which randomly picks an index in proportion to its weight.So if the input is like [1, 3], call pickIndex() five times, then the answer may come ... Read More

Contiguous Array in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 13:36:15

1K+ Views

Suppose we have a binary array, we have to find the maximum length of a contiguous subarray with equal number of 0 and 1. So if the input is like [0, 1, 0], then the output will be 2 as [0, 1] or [1, 0] is the largest contiguous array ... Read More

Longest Word in Dictionary through Deleting in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 13:30:40

218 Views

Suppose we have a string and a string dictionary, we have to find the longest string in the dictionary that can be formed by deleting some of the characters of the given string. If there are more than one possible results, then just return the longest word with the smallest ... Read More

Continuous Subarray Sum in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 13:27:06

1K+ Views

Suppose we have a list of non-negative numbers and a target integer k, we have to write a function to check whether the array has a continuous subarray of size at least 2 that sums up to a multiple of k, sums up to n*k where n is also an ... Read More

Random Flip Matrix in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 13:22:36

317 Views

Suppose we have a binary matrix with n_rows number of rows and n_cols number of columns. Here all values are initially 0. we have to define a function flip() which chooses a 0 value uniformly at random, changes it to 1, and then returns the position [row.id, col.id] of that ... Read More

Longest Palindromic Subsequence in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 13:18:59

815 Views

Suppose we have a string s, we have to find the longest palindromic subsequence's length in s. We can assume that the maximum length of s is 1000. So if the input is like “bbbab”, then output will be 4. One possible palindromic subsequence is “bbbb”.To solve this, we will ... Read More

Diagonal Traverse in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 13:12:56

1K+ Views

Suppose we have a matrix of M x N elements, we have to find all elements of the matrix in diagonal order. So if the matrix is like −123456789The output will be [1, 2, 4, 7, 5, 3, 6, 8, 9]To solve this, we will follow these steps −Make an ... Read More

Random Point in Non-overlapping Rectangles in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 13:09:50

328 Views

Suppose we have a list of non-overlapping axis-aligned rectangles rects, we have to write a function pick which randomly and uniformly picks an integer number, point in the space covered by the rectangles. So we have to keep in mind some points −An integer point is a point that has ... Read More

Teemo Attacking in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 13:06:27

112 Views

Suppose in LOL world, there is a hero named Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, suppose we have given the Teemo's attacking ascending time series towards Ashe and the poisoning time duration per Teemo's attacking, we have to find the total time ... Read More

Advertisements