Arnab Chakraborty has Published 4293 Articles

Brace Expansion in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 15:32:58

361 Views

Suppose we have a string S that represents a list of words. Here each letter in the word has 1 or more options. If there is only one option, the letter is represented as is. If there is more than one option, then curly braces delimit the options. So for ... Read More

Lexicographically Smallest Equivalent String in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 15:29:20

760 Views

Suppose we have strings A and B of the same length, now we can say A[i] and B[i] are equivalent characters. So for example, if A = "abc" and B = "cde", then we have 'a' = 'c', 'b' = 'd' and 'c' = 'e'. The equivalent characters follow the ... Read More

Longest Repeating Substring in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 15:28:46

2K+ Views

Suppose we have a string S, we have to find the length of the longest repeating substring(s). We will return 0 if no repeating substring is present. So if the string is like “abbaba”, then the output will be 2. As the longest repeating substring is “ab” or “ba”.Return all ... Read More

Missing Element in Sorted Array in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 15:18:32

445 Views

Suppose we have a sorted array A of unique numbers, we have to find the K-th missing number starting from the leftmost number of the array. So if the array is like [4, 7, 9, 10], and k = 1, then the element will be 5.To solve this, we will ... Read More

Minimize Rounding Error to Meet Target in C++

Arnab Chakraborty

Arnab Chakraborty

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

442 Views

Suppose we have an array of prices P [p1, p2..., pn] and a target value, we have to round each price Pi to Roundi(Pi) so that the rounded array [Round1(P1), Round2(P2)..., Roundn(Pn)] sums to the given target value. Here each operation Roundi(pi) could be either Floor(Pi) or Ceil(Pi).We have to ... Read More

Shortest Way to Form String in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 15:04:56

326 Views

Suppose we have a string, we can form a subsequence of that string by deleting some number of characters (possibly no deletions). So if there is two strings source and target, we have to find the minimum number of subsequences of source such that their concatenation equals target. If the ... Read More

Last Stone Weight II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 15:01:51

1K+ Views

Suppose we have a collection of rocks, now each rock has a positive integer weight. In each turn, we choose any two rocks and smash them together. If the stones have weights x and y with x = 0, decrease j by 1dp[j] := false when (dp[j] and dp[j – ... Read More

Longest String Chain in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 14:57:50

532 Views

Suppose we have a list of words, here each word consists of lowercase letters. So one word word1 is a predecessor of another word word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2. For the example of the predecessor ... Read More

Robot Bounded In Circle C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 14:54:21

314 Views

Suppose we have an infinite plane, a robot initially stands at position (0, 0) and faces north. The robot can receive one of three instructions −G − go straight 1 unit;L − turn 90 degrees to the left direction;R − turn 90 degrees to the right direction.The robot performs the ... Read More

Minimum Score Triangulation of Polygon in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 14:49:19

342 Views

Suppose we have a value N, consider a convex N-sided polygon with vertices labelled A[0], A[i], ..., A[N-1] are in clockwise order. Now suppose we want to triangulate the polygon into N-2 triangles. For each triangle, the value of that triangle is the product of the labels of the vertices, ... Read More

Advertisements