
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 1920 of 3368

157 Views
Suppose we have a string S, we have to count the number of distinct subsequences of S. The result can be large, so we will return the answer modulo 10^9 + 7.So, if the input is like "bab", then the output will be 6, as there are 6 different sequences, these are "a", "b, "ba", "ab", "bb", "abb".To solve this, we will follow these steps −Define a function add(), this will take a, b, return ((a mod MOD) + (b mod MOD)) mod MODDefine a function sub(), this will take a, b, return (((a mod MOD) - (b mod MOD)) ... Read More

191 Views
Suppose we have one array A of 0s and 1s, we have to divide the array into 3 non-empty parts such that all of these parts represent the same binary value. If that is possible, return any [i, j] with i+1 < j, such that −A[0], A[1], ..., A[i] is the first part;A[i+1], A[i+2], ..., A[j-1] is the second part, andA[j], A[j+1], ..., A[A.length - 1] is the third part.All three parts have equal binary value. If that is not possible, return [-1, -1].So, if the input is like [0, 1, 0, 1, 1], then the output will be [0, ... Read More

514 Views
Suppose we have a music player, that contains N different songs and we want to listen to L songs during our trip. So we have to make a playlist so that it meets these conditions −Every song is played at least onceA song can only be played again only if K other songs have been played.We have to find the number of possible playlists. The answer can be very large, so we will return it modulo 10^9 + 7.So, if the input is like N = 2, L = 3, K = 0, then the output will be 6, as ... Read More

527 Views
Suppose we have a positive integer N, that is said to be a superpalindrome if it is a palindrome, and it is also the square of a palindrome. Now consider we have two positive integers L and R we have to find the number of superpalindromes in the inclusive range of [L, R].So, if the input is like L = 5 and R = 500, then the output will be 3, the superpalindromes are 9, 121, 484.To solve this, we will follow these steps −Define a function helper(), this will take x, m, M, lb, ub, if x > ub, ... Read More

773 Views
Suppose we have a string S. This is a string of characters from the set {'D', 'I'}. (D means "decreasing" and I means "increasing")Now consider a valid permutation is a permutation P[0], P[1], ..., P[n] of integers {0 to n}, such that for all i, it meets these rules:If S[i] == 'D', then P[i] > P[i+1];Otherwise when S[i] == 'I', then P[i] < P[i+1].We have to find how many valid permutations are there? The answer may be very large, so we will return using mod 10^9 + 7.So, if the input is like "IDD", then the output will be 3, ... Read More

182 Views
Suppose we have one sorted set of digits D, a non-empty subset of {'1', '2', '3', '4', '5', '6', '7', '8', '9'} except 0. Now, we will write some numbers using these digits, using each digit as many times as we want. So, if D = {'2', '3', '7'}, we may write numbers such as '23', '771', '2372327'.Now we have to find the number of positive integers that can be written that are less than or equal to N.So, if the input is like D = [2, 3, 4, 7], N = 100, then the output will be 20, as ... Read More

230 Views
Suppose there is a string S. All letters in S are in lowercase. Then, we may make any number of moves.Here, in each move, we choose one of the first K letters, and remove it, and place it at the end of the string. We have to find the lexicographically smallest string we could have after any number of moves.So, if the input is like "cabaa" and K = 3, then the output will be "aaabc"To solve this, we will follow these steps −if K > 1, then −sort the array Sreturn Sret := Sn := size of Sfor initialize ... Read More

420 Views
Suppose we want to implement one stack called FreqStack, Our FreqStack has two functions −push(x), This will push an integer x onto the stack.pop(), This will remove and returns the most frequent element in the stack. If there are more than one elements with same frequency, then the element closest to the top of the stack is removed and returned.So, if the input is like push some elements like 7, 9, 7, 9, 6, 7, then perform the pop operations four times, then the output will be 7, 9, 7, 6 respectively.To solve this, we will follow these steps −Define ... Read More

184 Views
Suppose we have an array A of integers, consider all non-empty subsequences of A. For any sequence S, consider the width of S be the difference between the maximum and minimum element of S. We have to find the sum of the widths of all subsequences of A. The answer may be very large, so return the answer modulo 10^9 + 7.So, if the input is like [3, 1, 2], then the output will be 6, this is because the subsequences are like [1], [2], [3], [2, 1], [2, 3], [1, 3], [2, 1, 3] and the widths are 0, ... Read More

478 Views
Suppose we have given K eggs, and we have a building with N floors from 1 to N. Now each egg is identical in function, and if an egg breaks, we cannot drop it again.There exists a floor F with between 0 and N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floor F will not break. In each move, we may take an egg and drop it from any floor X. The X is in range 1 to N.Our goal is to know with certainty what the ... Read More