
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

921 Views
Suppose we have a complete binary tree, we have to count the number of nodes. So if the tree is like −So the output will be 6.To solve this, we will follow these stepsThis will use the recursive approach. This method, countNodes() is taking the root as argument.hr := 0 and hl := 0create two nodes l and r as rootwhile l is not emptyincrease hl by 1l := left of lwhile r is not emptyr := right of rincrease hr by 1if hl = hr, then return (2 ^ hl) – 1return 1 + countNodes(left of root) + countNodes(right ... Read More

177 Views
Consider we have to generate all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used. Each combination should be a unique set of numbers. All numbers should be positive, and the solution must not contain duplicate combinations. So if k = 3 and n = 9, then the possible combinations are [[1, 2, 6], [1, 3, 5], [2, 3, 4]]To solve this, we will follow these steps −Suppose we will solve this using forming a method called solve. This will be recursive method, this will take ... Read More

2K+ Views
Suppose we have an unsorted array, we have to find the kth largest element from that array. So if the array is [3, 2, 1, 5, 6, 4] and k = 2, then the result will be 5.To solve this, we will follow these steps −We will sort the element, if the k is 1, then return last element, otherwise return array[n – k], where n is the size of the array.Let us see the following implementation to get better understanding −Example Live Democlass Solution(object): def findKthLargest(self, nums, k): nums.sort() if k ==1: ... Read More

781 Views
Consider, you are a professional robber. And you are planning to rob houses along a street. Each house has a certain amount of money stored. All houses are arranged in a circle. That means the first house is the neighbor of the last house. We have to keep in mind that the adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night. So if we have a list of integers representing the amount of money of each house, determine the maximum amount of money you can ... Read More

5K+ Views
Suppose we have to make the trie structure, with three basic operations like insert(), search(), startsWith() methods. We can assume that all inputs are in lowercase letters. For example, if we call the functions as follows, we will see the outputsTrie trie = new Trie()trie.insert(“apple”)trie.search(“apple”) //This will return truetrie.search(“app”) //This will return falsetrie.startsWith(“app”) //This will return truetrie.insert(“app”)trie.search(“app”) //This will return trueTo solve this, we will follow these steps −Initially make one dictionary called child.The insert method will be like −current := childfor each letter l in word −if l is not present in ... Read More

2K+ Views
Suppose we have a grid, there are few 0s and few 1s. We have to count the number of islands. An island is place that is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. We can assume that all four edges of the grid are all surrounded by water.Suppose the grid is like −11000110000010000011There are three islands.To solve this, we will follow these steps −There will be two methods, one will be used to count number of islands called numIslands() and makeWater(). The makeWater() will be like −if number of rows in the grid is ... Read More

199 Views
Suppose we have a binary tree, if we see the tree from right side, then we can see some elements of it. we have to display those elements. So if the tree is like −To solve this, we will follow these steps −We will create one helping method for dfs. This will take tree_node, an array to hold answers, and level. The level is initially 0. The dfs will work like below −if node is null, then returnif level = length of the answer array, then insert value of node into the ans arraydfs(right of the node, ans, level + ... Read More

2K+ Views
Suppose we want to make one iterator for binary tree. There will be two methods. The next() method to return the next element, and hasNext() method to return Boolean value, that will indicate that the next element is present or not. So if the tree is like −And the sequence of function calls are [next(), next(), hasNext(), next(), hasNext(), next(), hasNext(), next(), hasNext()]. The output will be [3, 7, true, 9, true, 15, true, 20, false]To solve this, we will follow these steps −There are two methods next and hasNext, The next() method will be like −curr := stack top ... Read More

4K+ Views
A peak element in an array is defined as an element that is greater than its neighbors. We can use some common approaches such as binary search to efficiently locate a peak element and linear search algorithm which involves iterating through an array. Binary Search Approach The Binary Search is an efficient technique for locating a peak element in an array. To find a peak, follow these steps: Choose the middle element of the array. ... Read More

428 Views
In this tutorial, we will be discussing a program to find the numbers from 1 to n that have 4 as a digit.For this we will be provided with a number n. Our task is to count all the numbers which have 4 as one of their digits and print it out.Example Live Demo#include using namespace std; bool has4(int x); //returning sum of digits in the given numbers int get_4(int n){ int result = 0; //calculating the sum of each digit for (int x=1; x