Server Side Programming Articles - Page 1847 of 2650

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

272 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

279 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

485 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

616 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

426 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

Sentence Screen Fitting in C++

Arnab Chakraborty
Updated on 29-Apr-2020 15:09:43

219 Views

Suppose we have a rows x cols screen and a sentence represented by a list of non-empty words, so we have to find how many times the given sentence can be fitted on the screen. There are certain properties −A word will not be split into two lines.The order of words in the sentence must not be changed.There will be only one space between two words.The total number of words in the sentence won't exceed 100.The length of each word is greater than 0 but less than 10.1 ≤ rows, cols ≤ 20, 000.So if the input is like rows ... Read More

Remove K Digits in C++ program

Arnab Chakraborty
Updated on 29-Apr-2020 15:03:15

318 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], But the following sequence is not arithmetic. [1, 1, 2, 5, 7]Now a zero-indexed array A consisting of N numbers is given. A slice of that given array is any pair of integers (P, Q) such that 0

Remove K Digits in C++

Arnab Chakraborty
Updated on 31-Mar-2020 08:38:57

750 Views

Suppose we have a non-negative integer num that is represented as a string, we have to remove k digits from the number so that the new number is the smallest possible. So if the input is like “1432219” and k = 3, then the result will be “1219”.To solve this, we will follow these steps −Define a stack st, create an empty string retn := size of numfor i in range 0 to n – 1while k is non zero and stack is not empty and top of stack > num[i]delete from the stack and decrease k by 1insert num[i] ... Read More

Advertisements