
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
Found 26504 Articles for Server Side Programming

246 Views
Suppose we have a list of numbers called nums and another value k, we have to find the size of the longest increasing subsequence with at least k odd elements.So, if the input is like nums = [12, 14, 16, 5, 7, 8] k = 2, then the output will be 3, as the longest increasing subsequence with at least 2 odd values is [5, 7, 8].To solve this, we will follow these steps −best := 0Define a function dp() . This will take i, j, odd, takenif odd >= k, thenbest := maximum of best and takenif j is ... Read More

207 Views
Suppose we have a number n. Now consider an operation where we can either 1. Decrement n by one 2. If n is even number, then decrement it by n / 2 3. If n is divisible by 3, then decrement by 2 * (n / 3) Finally find the minimum number of operations required to decrement n to zero.So, if the input is like n = 16, then the output will be 5, as n = 16 even then decreases it by n/2 4 times, it will be 1. Then reduce it by 1 to get 0. So total ... Read More

446 Views
Suppose we have a number n, we have to find the next bigger permutation of its digits. When n is already in its largest permutation, then rotate it down to the smallest permutation.So, if the input is like n = 319, then the output will be 391.To solve this, we will follow these steps −Define a function makeArray(), this will take x, Define an array retwhile x is non-zero, do −insert x mod 10 at the end of retx := x / 10reverse the array retreturn retDefine a function combine(), this will take an array v, ret := 0for each ... Read More

257 Views
Suppose we have a binary matrix where 0 is representing empty cell and 1 is representing a chess queen at that cell. We have to check whether we can fill this board and get a valid nqueen solution or not. As we know the n queens puzzle asks to place n queens on an n × n chessboard so that no two chess queens can attack each other.So, if the input is like1000000000000010000000010then the output will be True, as one solution is like −1000000100000010100000010To solve this, we will follow these steps −Define a function isSafe() . This will take board, ... Read More

131 Views
Suppose we have a string s. This s consists of opening and closing parenthesis only. We have to find the length of the longest valid (well-formed) parentheses substring. So if the input is like “))(())())”, then the result will be 6, as the valid string is “(())()”.To solve this, we will follow these steps −Make a stack, and insert -1., set ans := 0for i in range 0 to length of stack – 1if s[i] is opening parentheses, then insert i into stackotherwiseif stack is not empty and top of stack is not -1 and s[stack top] is opening parentheses, ... Read More

360 Views
Suppose we have two lists of numbers. One is called weights and another is called values. These are of same length, We also have two values called capacity and count. Here weights[i] and values[i] represent the weight and value of the ith item. We can hold at most capacity weight and at most count items in total, and we can take only one copy of each item, so we have to find the maximum amount of value we can get.So, if the input is like weights = [2, 2, 4, 6] values = [15, 15, 20, 35] capacity = 8 ... Read More

213 Views
Suppose we have a string s that is representing the initial conditions of some animals. Each animal can take one of three values: L, indicates the animal moved to left. R, indicates the animal moved to right. @, indicates the animal is standing still. Animals moving on a direction will pick up other animals unless the animal receives a force from the opposite direction. Then, it will stand still. We have to find the orientation of each animal when the animal stop moving.So, if the input is like s = "@@L@R@@@@L", then the output will be "LLL@RRRLLL"To solve this, we ... Read More

422 Views
Suppose we have a binary string s. Now suppose we can take some prefix of s and move it to the back. then, find the minimum number of characters that need to be flipped such that there will be no consecutive characters of the same value.So, if the input is like s = "10010101111", then the output will be 2, as we can take prefix "10", then move it to back so string is "01010111110" then flip 3rd and 5th bit from right to 0 ("01010101010").To solve this, we will follow these steps −ans := size of SN := size ... Read More

123 Views
Suppose we have a list of numbers called nums that stored 0s and 1s. We have another value k.Now consider there is an operation where we flip a sublist of length k such that all 1s will be 0s and all 0s will be 1s. We have to find the minimum number of operations required to change nums into all 1s to 0s. If we cannot change it return -1.So, if the input is like nums = [1, 1, 1, 0, 0, 1, 1, 1], k = 3, then the output will be 2, as we can flip the first ... Read More

702 Views
Suppose we have a list of numbers called nums that are representing position of houses on a 1-dimensional line. Now consider we have 3 street lights that we can put anywhere on the line and a light at position x lights up all houses in range [x - r, x + r], inclusive. We have to find the smallest r required to light up all houses.So, if the input is like nums = [4, 5, 6, 7], then the output will be 0.5, as we can place the lamps on 4.5, 5.5 and 6.5 so r = 0.5. So these ... Read More