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 1022 of 3363
1K+ Views
Suppose we have two sentences s and t. We have to check whether they are similar or not. Here sentence has only English letters. Two sentences are said to be similar when it is possible to add an arbitrary sentence (possibly empty) inside one of these given sentences such that the two sentences become equal.So, if the input is like s = "we live at city Kolkata" t = "city Kolkata", then the output will be True because we can get s from t by adding sentence "we live in".To solve this, we will follow these steps −s1 := a ... Read More
526 Views
Suppose we have a number in string format, and we have to find the sum of all substrings of s. The answer may be very large, so return result modulo 10^9+7.So, if the input is like s = "268", then the output will be 378 as the substrings are "2", "6", "8", "26", "68" and "268" total sum is 378.To solve this, we will follow these steps −M := 10^9 + 7sum_val := 0B := 1res := 0for i in range size of s - 1 down to 0, decrease by 1, dores :=(res + digit value of s[i] * ... Read More
447 Views
Suppose we have a string s with parenthesis '(' , ')' and lowercase English characters. We have to delete the minimum number of parentheses ( '(' or ')', from any positions ) so that the resulting parentheses string is valid and have to finally return any valid string. Here the parentheses string is valid when all of these criteria are fulfilled −The string is empty and contains lowercase characters only, orThe string can be written as AB (A concatenated with B), where A and B are valid strings, orThe string can be written as the form of (A), where A ... Read More
407 Views
Suppose we have to find an array of size N such that the absolute difference between every two consecutive digits is K. Every number in the answer must not have leading zeros except for the number 0 itself.So, if the input is like N = 4 K = 7, then the output will be [1818, 2929, 7070, 8181, 9292], here 0707 is not valid as it has leading 0.To solve this, we will follow these steps −if N is same as 1, thenreturn a new list from range 0 to 9queue := make a queue with all elements from 1 ... Read More
2K+ Views
Suppose, we have an array called nums and we have to find the number of swaps needed to make nums sorted in any order, either ascending or descending.So, if the input is like nums = [2, 5, 6, 3, 4], then the output will be 2 because initially nums has [2, 5, 6, 3, 4]. If we swap numbers 6 and 4, the array will be [2, 5, 4, 3, 6]. Then, if we swap the numbers 5 and 3, the array will be [2, 3, 4, 5, 6]. So 2 swaps are needed to make the array sorted in ... Read More
294 Views
Suppose we have an array nums, we have to partition it into two different subarrays called left and right such that −Each element in left subarray is less than or equal to each element in right subarray.left and right subarrays are non-empty.left subarray has the smallest possible size.We have to find the length of left after such a partitioning.So, if the input is like nums = [5, 0, 3, 8, 6], then the output will be 3 because left array will be [5, 0, 3] and right subarray will be [8, 6].To solve this, we will follow these steps −mx ... Read More
483 Views
Suppose we have an array called coins with n elements, and it is representing the coins that we own. The value of the ith coin is denoted as coins[i]. We can make some value x if we can select some of our n coins such that their values sum up to x. We have to find the maximum number of consecutive values that we can get with the coins starting from and including 0.So, if the input is like coins = [1, 1, 3, 4], then the output will be 10, because0 = []1 = [1]2 = [1, 1]3 = ... Read More
360 Views
Suppose there are m boys and n girls, and m = n. There is a party incoming, and each boy has to go with a girl to that party. So, the boys invite all the girls and a girl can accept one invitation only. We have to find out the total number of invitations from the boys that the girls can accept. The input is given in a m x n matrix, where each cell position i, j denotes if the boy i has sent a letter to girl j. If a cell is 1 it means that an invitation ... Read More