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 1919 of 3366
261 Views
Suppose we have an array A of positive integers, we can call a good subarray (contiguous) of A, if the number of different integers in that subarray is exactly K. So, if the array is like [1, 2, 3, 1, 2] has 3 different integers: 1, 2, and 3. We have to find the number of good subarrays of A.So, if the input is like [1, 2, 3, 1, 4] and K = 3, then the output will be 4, as it can form three subarrays with exactly four distinct integers, these are [1, 2, 3], [1, 2, 3, 1], ... Read More
217 Views
Suppose we have two strings, these are S and T, each of which represents a positive rational number, We have to check whether they represent the same number or now. The strings may use parentheses to denote the repeating part of the rational number.As we know that rational numbers can be represented using up to three parts: an integer part, a non-repeating part, and a repeating part. The number will be represented in one of the following three ways −Only integer part (like 0, 12, 123)IntegerPart.NonRepeatingPart (like 0.5, 1.0, 2.12, 2.0001)IntegerPart.NonRepeatingPart(RepeatingPart>) (like 0.1(6), 0.9(9), 0.00(1212))For example Both 0.1(6) or 0.1666(6) ... Read More
336 Views
Suppose we have a positive integer x, we will write an expression of the form x (op1) x (op2) x (op3) x ... where op1, op2, etc. are the operators. And these operators can be either addition, subtraction, multiplication, or division. For example, with x = 3, we might write 3 * 3 / 3 + 3 - 3 which is a value of 3. There are few some rules, these are as follows -The division operator (/) returns rational numbers.There are no parentheses placed anywhere.We use the usual order of operations − multiplication and division has higher priority than ... Read More
244 Views
Suppose we have an array A of N strings. Each string is consists of lowercase letters, all are of same length. Now, we can choose any set of deletion indices, and for each string, we will delete all the characters in those indices.Now consider we have taken a set of deletion indices D such that after deletions, the final array has every element in lexicographic sequence.For clarity, A[0] is in lexicographic order (So A[0][0]
156 Views
Suppose we are installing a billboard and we want it to have the largest height. The billboard will have two steel supports on both sides. Each support must be of equal height. We also have a collection of rods which can be welded together. So, if we have rods of lengths 1, 2, and 3, we can weld them together to make a support of length 6. We have to find the largest possible height of our billboard installation. If we cannot support the billboard, return 0.So, if the input is like [1, 2, 2, 3, 3, 3, 4], then ... Read More
189 Views
Suppose we have an array A of unique positive integers, now consider the following graph −There are length of A number of nodes, these are labelled A[0] to A[size of A - 1]; There is an edge between A[i] and A[j] when A[i] and A[j] share a common factor greater than 1. We have to find the size of the largest connected component in the graph.So, if the input is like [4, 6, 15, 35], then the output will be 4To solve this, we will follow these steps −Define an array parentDefine an array rankDefine an array rankif parent[x] is ... Read More
399 Views
Suppose we have an array A of strings, we have to find any smallest string that contains each string in A as a substring. We can also assume that no string in A is substring of another string in A.So, if the input is like ["dbsh", "dsbbhs", "hdsb", "ssdb", "bshdbsd"], then the output will be "hdsbbhssdbshdbsd"To solve this, we will follow these steps −Define a function calc(), this will take a, b, for initialize i := 0, when i < size of a, update (increase i by 1), do −if substring of a from index i to end is at ... Read More
162 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
195 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