Arnab Chakraborty has Published 4293 Articles

Minimum Swaps to Group All 1's Together in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 06:02:01

340 Views

Suppose we have a binary array data, we have to find the minimum number of swaps required to group all 1’s stored in the array together in any place in the array. So if the array is like [1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1], then ... Read More

Number of Matching Subsequences in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 06:00:45

334 Views

Suppose we have a string S and a dictionary of words words, find the number of words[i] that is a subsequence of S. So if the input is S= “abcde” and dictionary is [“a”, “bb”, “acd”, “ace”], then output will be 3. Because there are three sequence of words in ... Read More

Reorganize String in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 05:57:20

640 Views

Suppose we have a string S, check whether the letters can be rearranged so that two characters that are adjacent to each other are not the same. If that is possible, output any possible result. If that is not possible, return the empty string. So if the input is like ... Read More

Snapshot Array in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 05:56:46

599 Views

Suppose we have to Implement a SnapshotArray that supports the following interfaces −SnapshotArray(int length) this will initialize the array-like data structure with the given length. Initially, each element equals 0.set(index, val) this will sets the element at the given index to be equal to val.snap() will take a snapshot of ... Read More

Kth Smallest Element in a Sorted Matrix in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 05:54:09

450 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 ... Read More

Ugly Number III in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 16:38:57

235 Views

Suppose we have to write a program to find the n-th ugly number. The Ugly numbers are positive integers which are divisible by a or b or c. So for example, if n = 3 and a = 2, b = 3 and c = 5, then the output will ... Read More

Find Smallest Common Element in All Rows in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 16:35:19

209 Views

Suppose we have a matrix mat where every row is sorted in non-decreasing order, we have to find the smallest common element in all rows. If there is no common element, then return -1. So if the matrix is like −1234524581035791113579The output will be 5To solve this, we will follow ... Read More

Minimum Knight Moves in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 16:32:23

868 Views

Suppose we have an infinite chessboard with coordinates from -infinity to +infinity, and we have a knight at square [0, 0]. A knight has 8 possible moves it can make, as shown below. Each move is two squares in a cardinal direction, then one square in an orthogonal direction.We have ... Read More

Reverse Substrings Between Each Pair of Parentheses in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 16:28:04

376 Views

Suppose we have a string s that consists of lower case letters and brackets. We have to reverse the strings in each pair of matching parentheses, starting from the innermost one. And the result should not contain any brackets. So if the input is like "(hel(lowo)rld)", then the output will ... Read More

Shortest Distance to Target Color in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 29-Apr-2020 16:23:16

252 Views

Suppose we have an array color, in which there are three colors: 1, 2 and 3. We have given some queries. Each query consists of two integers i and c, we have to find the shortest distance between the given index i and the target color c. If there is ... Read More

Advertisements