Found 26504 Articles for Server Side Programming

Reverse Substrings Between Each Pair of Parentheses in C++

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 be "dlrlowoleh", so from the beginning, it is changed like: "(hel(lowo)rld)" → "(helowolrld)" → “dlrowoleh”.To solve this, we will follow these steps −n := size of string, make an array called par whose length is n, define a stack stfor i in range 0 to n – 1if s[i] is ... Read More

Shortest Distance to Target Color in C++

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

254 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 no solution, then return -1. So if the colors array is like [1, 1, 2, 1, 3, 2, 2, 3, 3], and the queries array is like [[1, 3], [2, 2], [6, 1]], the output will be [3, 0, 3]. This is because the nearest 3 from index 1 is ... Read More

Before and After Puzzle in C++

Arnab Chakraborty
Updated on 29-Apr-2020 16:18:40

161 Views

Suppose we have a list of phrases, generate a list of Before and After puzzles. Here a phrase is a string that consists of lowercase letters and spaces only. No space will be there at the starting and ending positions. There are no consecutive spaces in a phrase.The before and after puzzles are phrases that are formed by merging two phrases where the last word of the first phrase is the same as the first word of the second phrase. We have to find the Before and After puzzles that can be formed by every two phrases phrases[i] and phrases[j] ... Read More

Convex Polygon in C++

Arnab Chakraborty
Updated on 29-Apr-2020 16:12:32

2K+ Views

Suppose we have a list of points that form a polygon when joined sequentially, we have to find if this polygon is convex (Convex polygon definition). We have to keep in mind that there are at least 3 and at most 10, 000 points. And the coordinates are in the range -10, 000 to 10, 000.We can assume the polygon formed by given points is always a simple polygon, in other words, we ensure that exactly two edges intersect at each vertex and that edges otherwise don't intersect each other. So if the input is like: [[0, 0], [0, 1], ... Read More

Validate IP Address in Python

Arnab Chakraborty
Updated on 29-Apr-2020 16:08:17

2K+ Views

Suppose we have a string; we have to check whether the given input is a valid IPv4 address or IPv6 address or neither.The IPv4 addresses are canonically represented in dotted-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255, separated by dots ("."), For example, 192.168.254.1; Besides, leading zeros in the IPv4 address is invalid. For example, the address 192.168.254.01 is invalid.The IPv6 addresses are represented as eight groups of four hexadecimal digits, each group representing 16 bits. The groups are separated by colons (":"). For example, suppose the address is 2001:0db8:85a3:0000:0000:8a2e:0370:7334 is a valid address. ... Read More

Unique Substrings in Wraparound String in C++

Arnab Chakraborty
Updated on 29-Apr-2020 16:04:17

260 Views

Suppose we have the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so the value s will look like this − "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".Now we have another string p. Our job is to find out how many unique non-empty substrings of p are present in s. In particular, our input is the string p and we need to output the number of different non-empty substrings of p in the string s.So if the input is like “zab” the output will be 6. There are 6 substrings “z”, “a”, “b”, “za”, “ab”, “zab” of the string “zab” in the string sTo ... Read More

Can I Win in C++

Arnab Chakraborty
Updated on 29-Apr-2020 16:01:45

271 Views

Suppose in a game called "100 games, " two players take turns adding, to a running total, any integer from 1 through 10. The player who first causes the running total to reach or exceed 100, he/she wins. So what if we change the game so that players cannot re-use integers?For example, if two players take turns drawing from a common pool of numbers of 1..15 without replacement until they reach a total >= 100.So suppose given an integer maxChoosableInteger and another integer desired total, determine if the first player to move can force a win, assuming both players play ... Read More

132 Pattern in C++

Vivek Verma
Updated on 28-Aug-2025 14:10:10

470 Views

The 132 pattern indicates that, as the digits in "132" in any given value, the middle element should be greater than the last and first elements. Similarly, the last element must be greater than the first element. To check 132 patterns in C++, we will use the Array data structure. We have given an array nums[] of size S. Our task is to check whether the array elements at indices i, j, and k are such that i < j < k and nums[j] < nums[k] and nums[i] < nums[k]. If any three elements at positions i < j < k ... Read More

Ternary Expression Parser in C++

Arnab Chakraborty
Updated on 29-Apr-2020 15:19:24

603 Views

Suppose we have a string representing arbitrarily nested ternary expressions, we have to calculate the result of the expression. we can always assume that the given expression is valid and only consists of digits 0-9, ?, :, T and F these few characters. (Here T and F represent True and False respectively). There are some properties −The length of the given string must be less than or equal to 10000.Each number will contain only one digit.The conditional expressions group right-to-left.The condition will always be either T or F. So the condition will never be a digit.The result of the expression ... Read More

Find Right Interval in C++

Arnab Chakraborty
Updated on 29-Apr-2020 15:13:23

416 Views

Suppose we have a of intervals, for each of the interval i, check whether there exists an interval j whose start point is bigger than or equal to the endpoint of the interval i, which can be called that j is on the "right" of i. For any interval i, we have to store the minimum interval j's index, which indicates that the interval j has the minimum start point to build the "right" relationship for interval i. When the interval j doesn't exist, then store -1 for the interval i. And finally, we need output the stored value of ... Read More

Advertisements