Arnab Chakraborty has Published 4293 Articles

Integer Replacement in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 08:31:38

705 Views

Suppose we have a positive integer n and we can do these operations as follow −If n is even, replace n with n/2.If n is odd, you can replace n with either n + 1 or n - 1.We have to find the minimum number of replacements needed for n ... Read More

Rotate Function in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 08:29:25

330 Views

Suppose we have Given an array of integers A and let n is the length of array A. Now assume Bk to be an array obtained by rotating the array A, k positions clock-wise. Here the rotation can be defined as −F(k) = 0 * Bk[0] + 1 * Bk[1] ... Read More

UTF-8 Validation in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 08:26:28

3K+ Views

Suppose we have a list integers representing the data. We have to check whether it is valid UTF-8 encoding or not. One UTF-8 character can be 1 to 4-byte long. There are some properties −For 1-byte character, the first bit is a 0, followed by its unicode code.For n-bytes character, ... Read More

Elimination Game in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 08:19:56

881 Views

Suppose we have a list of sorted integers from 1 to n. That is starting from left and ending at right, we have to remove the first number and every other number afterward until we reach the end of the list. We will repeat the previous step again, but this ... Read More

Linked List Random Node in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 08:17:15

395 Views

Suppose we have a singly linked list, we have to find a random node's value from the linked list. Here each node must have the same probability of being chosen. So for example, if the list is [1, 2, 3], then it can return random node in range 1, 2, ... Read More

Wiggle Subsequence in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 08:14:05

304 Views

Suppose we have a sequence of numbers that is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference may be either positive or negative. A sequence with less than two elements is trivially a wiggle sequence. So for example, [1, ... Read More

Super Pow in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 08:11:59

538 Views

Suppose we have to calculate a^b mod 1337 where a is one positive integer and b is an extremely large positive integer given in the form of an array. So if a = 2 and b = [1, 0] then the output will be 1024To solve this, we will follow ... Read More

Largest Divisible Subset in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 08:08:35

126 Views

Suppose we have a set of distinct positive integers, we have to find the largest subset such that every pair like (Si, Sj) of elements in this subset satisfies: Si mod Sj = 0 or Sj mod Si = 0.So if the input is like [1, 2, 3], the possible ... Read More

Water and Jug Problem in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 08:04:37

2K+ Views

Suppose we have two jugs with capacities x and y liters. There is an infinite amount of water supply available to us. Now we need to determine whether it is possible to measure exactly z liters using these two jugs. If z liters of water are measurable, we must have ... Read More

Count Numbers with Unique Digits in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 02-May-2020 08:01:38

1K+ Views

Suppose we have a non-negative integer n. We have to count all numbers with unique digits x, where x is in range 0 to 10^n. So if the number n is 2, then the result will be 91, as we want to find numbers from 0 to 100 without 11, ... Read More

Advertisements