
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

8K+ Views
Suppose we have a binary search tree. we have to write only one method, that performs the insertion operation with a node given as a parameter. We have to keep in mind that after the operation, the tree will remain BST also. So if the tree is like −if we insert 5, then the tree will be −To solve this, we will follow these steps −This method is recursive. this is called insert(), this takes a value v.if root is null, then create a node with given value v and make that as rootif value of root > v, thenleft ... Read More

441 Views
Suppose we have an array of integers called nums and a positive integer k, check whether it's possible to divide this array into k non-empty subsets whose sums are all same. So if the array is like [4, 3, 2, 3, 5, 2, 1] and k = 4, then the result will be True, as the given array can be divided into four subarray like [[5], [1, 4], [2, 3], [2, 3]] with equal sums.To solve this, we will follow these steps −define two table called dp and total of size 2^n, sort the given array nums, set sum := ... Read More

585 Views
Suppose we have a non-empty list of words; we have to find the k most frequent elements. our answer should be sorted by frequency from highest to lowest. When two words have the same frequency, then the word with the lower alphabetical order will be placed at first. So if the array is like [‘the’, ‘sky’, ‘is’, ‘blue’, ‘the’, ‘weather’, ‘is’, ‘comfortable’], so most frequent words are ["is", "the", "blue"]To solve this, we will follow these steps −Define one map called mcreate one priority queue vfor i := 0 to n, where n is the size of the word array, ... Read More

420 Views
Suppose we have one unsorted array of integers. we have to find the number of longest increasing subsequence, so if the input is like [1, 3, 5, 4, 7], then the output will be 2, as increasing subsequence are [1, 3, 5, 7] and [1, 3, 4, 7]To solve this, we will follow these steps −n := size of the num array, create two arrays len and cnt of size n, and fill them with value 1.lis := 1for i in range 1 to nfor j in range 0 to i – 1if nums[i] > nums[j], thenif len[j] + 1 ... Read More

1K+ Views
Suppose we have a non-negative integer; we could swap two digits at most once to get the maximum valued number. We have to return the maximum valued number we can get. So if the input is like 2736 then the output will be 7236. So here we are swapping 2 and 7.To solve this, we will follow these steps −num := cut each digit from the number, and make a listnum1 := sort the num in reverse orderindex := 0while index < length of numif num1[index] is not same as num[index]a := subarray of num from index (index + 1) ... Read More

464 Views
Suppose we have a sorted array, two integers k and x are also given, we have to find the k closest elements to x in that array. The result should be sorted in increasing order. If there is a tie, the smaller elements are always preferred. So if the input is like [1, 2, 3, 4, 5] and k = 4, x = 3, then output will be [1, 2, 3, 4]To solve this, we will follow these steps −Make an array called ansset low := 0, high := size of the array – kwhile low < highmid := low ... Read More

6K+ Views
Suppose we have a string; we have to count how many palindromic substrings present in this string. The substrings with different start indices or end indices are counted as different substrings even they consist of same characters. So if the input is like “aaa”, then the output will be 6 as there are six palindromic substrings like “a”, “a”, “a”, “aa”, “aa”, “aaa”To solve this, we will follow these steps −count := 0for i in range 0 to length if stringfor j in range i + 1 to length of string + 1temp := substring from index i to jif ... Read More

291 Views
Suppose we have two words w1 and w2, we have to find the minimum number of steps required to make w1 and w2 the same, where in each step we can delete one character in either string. So if the input is like “sea” and “eat”, then the output will be 2, because we need to delete ‘s’ from w1, this will be “ea” and delete “t” from “eat” from w2. Then they are the same.To solve this, we will follow these stepsn := size of s1, m := size of s2add one blank space before the strings s1 and ... Read More

703 Views
Suppose we have two strings s1 and s2, we have to write a function to return true if s2 contains the permutation of s1. So we can say that one of the first string's permutations is the substring of the second string. So if the string s1 = “abc”, and second string s2 is “findcab”, then the result will be true, as the permutation of “abc” is true. That is “cab”.To solve this, we will follow these steps −create two vectors cnt1 and cnt2 of size 26for i in range 0 to s1increase the value of cnt1[s1[i] – ‘a’] by ... Read More

786 Views
Suppose we have an array of integers and an integer k, we need to find the total number of continuous subarrays whose sum same as k. So if nums array is [1, 1, 1] and k is 2, then the output will be 2.To solve this, we will follow these steps −define one map called sums, temp := 0, sums[0] := 1 and ans := 0for i in range 0 to size of the arraytemp := temp + n[i]if sums has k – temp, thenans := ans + sums[k - temp]increase the value of sums[-temp] by 1return ansExample(C++)Let us see ... Read More