
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

1K+ Views
Suppose we have the inorder and preorder traversal sequence of a binary tree. We have to generate the tree from these sequences. So if the preorder and inorder sequences are [3, 9, 20, 15, 7] and [9, 3, 15, 20, 7], then the tree will be −Let us see the steps −Suppose the method is called buildTree with preorder and inorder listsroot := first node from the preorder, and delete first node from preorderroot_index := index of root.val from the inorder listleft or root := buildTree(preorder, subset of inorder from 0 to root_index)right or root := buildTree(preorder, subset of inorder ... Read More

260 Views
Suppose we have a linked list. We have to reverse the nodes from position m to n. We have to do it in one pass. So if the list is [1, 2, 3, 4, 5] and m = 2 and n = 4, then the result will be [1, 4, , 3, 2, 5]Let us see the steps −There will be two methods, the reverseN() and reverseBetween(). The reverseBetween() will work as main method.define one link node pointer called successor as nullThe reverseN will work as follows −if n = 1, then successor := next of head, and return headlast ... Read More

349 Views
In this problem, we are given a number N. Our task is to print all prime triplets less than N.Prime triplet is a set of three prime numbers. That are of the form (p, p+2, p+6) or (p, p+4, p+6). All prime numbers are grouped according to the above triplets as every third prime in the direct pattern is a multiple of 6.Let’s see an example to understand the problemInput: N = 13 Output: 5 7 11To solve this problem, we have to find all prime numbers less than equal to N. And the check for triplets.The code to show ... Read More

1K+ Views
In this problem, we are given a prime number N. our task is to print the primitive root of prime number N modulo N.Primitive root of prime number N is an integer x lying between [1, n-1] such that all values of xk (mod n) where k lies in [0, n-2] are unique.Let’s take an example to understand the problem, Input: 13 Output: 2To solve this problem, we have to use mathematical function called Euler’s Totient Function.Euler’s Totient Function is the count of numbers from 1 to n which are relatively prime to the number n.A number i is relatively ... Read More

433 Views
Suppose we have a set of numbers; we have to generate all possible subsets of that set. This is also known as power set. We have to keep in mind that the elements may be duplicate. So if the set is like [1, 2, 2], then the power set will be [[], [1], [2], [1, 2], [2, 2], [1, 2, 2]]Let us see the steps −Define one array res and another set called xWe will solve this using recursive approach. So if the recursive method name is called solve(), and this takes index, one temporary array, and the array of ... Read More

502 Views
In this problem, we are given a number n. Our task is to print its primorial number.Primorial number (Pn#) is a number that is the product of first n prime numbers.Primorial number is similar to factorial of a number n. The difference is that factorial can be any number but in case of primorial number, all prime numbers are used.Let’s take an example to understand the problem, Input: N = 4 Output 210 Explanation: Primorial number, Pn# = 2 * 3 * 5 * 7 = 210To solve this problem, we have to find the first n prime numbers. Print ... Read More

300 Views
Suppose we have a list of some elements. We have to remove all elements that have occurred more than once. So only the distinct elements will remain in the list. So if the list is like [1, 1, 1, 2, 2, 3, 5, 6, 6, 7, 8], then the output will be [3, 5, 7, 8], all other elements are present more than once.Let us see the steps −Create a dummy node with value -1, prev := NULL, dummyPtr := dummywhile head is not nullif next of head is present or the value of head is not same as the ... Read More

639 Views
In this problem, we are given a string password. Our task is to print * in place of characters of the password.Let’s take an example to understand the problem,Input: password Output ********To solve this problem, we will traverse the password we have entered and print * in place of characters of the password.ExampleThe below program will show the implementation of our solution Live Demo#include #include int main() { char password[50] = "password"; int length = strlen(password); printf("Password : "); for(int i = 0; i

429 Views
In this problem, we are given two numbers n and k. Our task is to print the kth least significant bit of the number n.Let’s take an example to understand the problemInput: n = 12 , k = 3 Output 1 Explanation: Let’s see the binary representation of n: 12 = 1100Now, 3rd least significant bit is 1.To solve this problem we will use the binary bits of the number. And yield the kth bit of the number. For this, we will use binary shifting of the number and left-shift the number (k-1) times. Now on doing end operation of ... Read More

242 Views
Consider we have an array sorted in ascending order. That is rotated at some pivot unknown to us beforehand. For example, if the array is like [0, 0, 1, 2, 2, 5, 6], this might become [2, 5, 6, 0, 0, 1, 2]. We have a target value to search. If that is found in the array, then return true, otherwise return false. So if the array is like [2, 5, 6, 0, 0, 1, 2], and target is 0, then the output will be 0Let us see the steps −low := 0 and high := size of arraywhile low ... Read More