Arnab Chakraborty has Published 4293 Articles

Minimum Size Subarray Sum in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 09:38:26

2K+ Views

Suppose we have an array of n elements, and a positive integer s. We have to find the minimal length of a contiguous subarray, of which the sum is greater or equal to s. If there isn’t one, then return 0 instead. So if the array is like [2, 3, ... Read More

Tree Diameter in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 09:38:13

1K+ Views

Suppose we have an undirected tree; we have to find its diameter − the number of edges in the longest path in that tree is the diameter of that tree. Here tree is given as an edge list where edges[i] = [u, v] is a bidirectional edge between nodes u ... Read More

Fraction to Recurring Decimal in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 09:36:18

1K+ Views

Suppose we have two integers representing the numerator and denominator of a fraction, we have to find fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. So if the numerator is 2 and denominator is 3, then the output will be “0.(6)”To solve ... Read More

Reorder List in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 09:35:15

913 Views

Suppose we have a linked list like l1 -> l2 -> l3 -> l4 -> … -> l(n-1) -> ln. We have to rearrange this list into the form l1 -> ln -> l2 -> l(n - 1) -> … and so on. Here the constraint is that, we cannot ... Read More

Sort List in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 09:29:28

264 Views

Suppose we have a list, we have to sort this in O(n logn) time using constant space complexity, so if the list is like [4, 2, 1, 3], then it will be [1, 2, 3, 4]To solve this, we will follow these steps −Define a method for merging two lists ... Read More

Flatten Binary Tree to Linked List in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 09:21:28

225 Views

Suppose we have a binary tree; we have to flatten it into linked list in place. So if the tree is like −The output tree will be −To solve this, we will follow these steps −ser prev := nullDefine a recursive function solve(), that will take root as input.if root ... Read More

Binary Tree Zigzag Level Order Traversal in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 09:13:33

748 Views

Suppose we have a binary tree; we have to find the Zigzag level order traversal. So for the first row, scan from left to right, then right to left from the second row, then again left to right and so on. So if the tree is like −The traversal sequence ... Read More

Task Scheduler n C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 08:47:54

4K+ Views

Suppose we have a char array representing tasks CPU need to do. This contains uppercase letters A to Z where different letters represent different tasks. The tasks could be done without original order. Each task could be done in one interval. For each interval, CPU could finish one job or ... Read More

Arithmetic Slices in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 08:07:41

256 Views

Suppose we have a sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. So for example, these are arithmetic sequence: [1, 3, 5, 7, 9], [7, 7, 7, 7], [3, -1, -5, -9], ... Read More

Smallest Integer Divisible by K in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 07:52:31

337 Views

Suppose we have a positive integer K, we need find the smallest positive integer N such that N is divisible by K, and N only contains the digit 1. We have to find the length of N. If there is no such N, return -1. So if the input is ... Read More

Advertisements