Arnab Chakraborty has Published 4293 Articles

The Maze in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 10:05:40

4K+ Views

Suppose there is a ball in a maze with empty spaces and walls. Now the ball can go through empty paths by rolling any direction like up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.We ... Read More

Max Consecutive Ones II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 10:00:51

1K+ Views

Suppose we have a binary array; we have to find the maximum number of consecutive 1s in this array if we can flip at most one 0.So, if the input is like [1, 0, 1, 1, 0], then the output will be 4 because if we flip the first zero ... Read More

Find Permutation in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 09:58:36

357 Views

Suppose we have a secret signature consisting of character 'D' and 'I'. 'D' denotes the decreasing relationship between two numbers, 'I' denotes increasing relationship between two numbers. And the secret signature was constructed by a special integer array, which contains uniquely all the different number from 1 to n.For example, ... Read More

Sequence Reconstruction in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 09:56:33

253 Views

Suppose we have to check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. The original sequence is a permutation of the integers from 1 to n, and n in range 1 ≤ n ≤ 10^4. Here the reconstruction means making a shortest common supersequence ... Read More

Design Phone Directory in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 09:52:43

602 Views

Suppose we want to design a Phone Directory which supports the following operations −get − This will provide a number that is not assigned to anyone.check − This will check whether a number is available or not.release − This will recycle or release a number.Using the initializer, we can initialize ... Read More

Range Addition in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 09:50:25

234 Views

Suppose we have an array of size n and that is initialized with 0's and we also have a value k, we will perform k update operations. Each operation will be represented as triplet: [startIndex, endIndex, inc] which increments each element of subarray A[startIndex ... endIndex] (startIndex and endIndex inclusive) ... Read More

Plus One Linked List in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 09:48:16

238 Views

Suppose we have a non-negative integer represented as non-empty a singly linked list of digits, now we have to plus one to the integer. We may assume the integer do not contain any leading zero, except the number 0 itself. In the linked list the most significant digit is at ... Read More

Find Leaves of Binary Tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 09:45:51

650 Views

Suppose we have a binary tree. We will collect and remove all leaves and repeat until the tree is empty.So, if the input is likethen the output will be [[4, 5, 3], [2], [1]]To solve this, we will follow these steps −Define one map szDefine one 2D array retDefine a ... Read More

Nested List Weight Sum II in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 09:43:00

294 Views

Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer, or a list -- whose elements may also be integers or other lists. Different from the previous question where weight is increasing from root to ... Read More

Design Hit Counter in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Nov-2020 09:39:49

679 Views

Suppose we want to design a hit counter which counts the number of hits received in the past 5 minutes. There will be a function and that accepts a timestamp parameter in the second unit and we may assume that calls are being made to the system in chronological order ... Read More

Advertisements