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 2179 of 3366
353 Views
Suppose there is an n x n matrix mat of integers. we have to find maximum value of mat(c, d) - mat(a, b) over all choices of indexes. Here we have to keep in mind that c > a and d > b. So if the matrix is like −12-1-4-20-8-342138613-4-117-60-410-51The output will be 18. This is because mat[4, 2] - mat[1, 0] = 18 has maximum difference.To solve this we will preprocess the matrix such that index(i, j) stores max of elements in matrix from (i, j) to (n - 1, n - 1) and in the process keeps on ... Read More
373 Views
In this problem, we are given an array of integers and we have to print only those numbers that are divisible by at least one other element of the array.Let’s take an example to understand the concept better, Input : 3 12 16 21 Output : 12 21Explanation − 3 is the smallest so it can be divisible by any other number are 12 which is divisible by 3, 16 not divisible by 3 and then 21 which is divisible by 3. So, we will neglect 3 and 16.One easy way is to check if all elements are divisible ... Read More
211 Views
Suppose we have a string A, we have to find another string B, that will be palindrome. And the given string A will be subsequence of B. The subsequence of a string is a string that can be formed by it by deleting some characters without changing the order of remaining characters. Suppose the string is “cotst”, then generated string will be “contest”. For the input of this program we have chosen A = “ab”, the generated string will be “abba”, this is palindrome.To solve this, we will follow this approach. This is very simple, we will reverse the A, ... Read More
536 Views
In the problem to print an array of strings in sorted order without copying one string into another, we need to sort the array of string. Here the programmer cannot copy a string into another string while sorting.Let’s take an example to understand the concept better :Example −Input : {“Delhi”, “Hyderabad”, “Indore”, “Mumbai”, “Banglore”} Output : Banglore, Delhi, Hyderabad, Indore, MumbaiExplanation − Lexicographically the ordering is done. So, Bangalore starting with B comes first and Mumbai starting with M comes last.Now, let's try to derive a solution to our problem.To solve the problem, we can create an array that stores the ... Read More
1K+ Views
In this problem, we are given a binary tree and we have to print it two dimensional plane.Binary Tree is a special tree whose every node has at max two child nodes. So, every node is either a leaf node or has one or two child nodes.Example, Let’s take an example to understand the topic better −Output - 7 4 5 1 3 8Now as we have seen in the example, the nodes of the tree are printed in a 2-D output screen horizontally.Here, we have flipped the tree by ... Read More
328 Views
Suppose we have a matrix where each row is sorted. We have to write a function that will find the common elements in each row. Suppose the matrix is like below −The result will be 5.To solve this, we will use hash based approach. This approach can also be used when the rows are not sorted. We have to follow some steps to do this −We will create one hash table with all keys as distinct elements of two 1. All values will be 0loop through each element in the matrix, if the number is present in the hash table ... Read More
842 Views
A FileFilter is a functional interface from the "java.io" package. It can be used as the assignment target for a lambda expression or method reference. An instance of the FileFilter interface passed to the listFiles() method of the File class. FileFilter interface having one abstract method accept() and it tests whether or not the specified abstract pathname has included in a pathname list.Syntax@FunctionalInterface public interface FileFilterExampleimport java.io.File; import java.io.FileFilter; public class FileFilterTest { public static void main(String[] args) { File dir = new File("C:/Program Files/Java/jdk1.8.0_211"); File[] subDir = dir.listFiles((file) -> { // lambda expression ... Read More
206 Views
In this problem, we are given a binary tree and we have to print all nodes at a level in sorted order of their values.Let’s take an example to understand the concept better, Input −Output −20 6 15 2 17 32 78To solve this problem, we need to print a sorted order of each level of the tree. For this, we need to create a queue and two priority queues. The NULL separator is used to separate two levels.ExampleProgram to illustrate the logic − Live Demo#include #include #include using namespace std; struct Node { int data; struct ... Read More
151 Views
In this problem, we have to print all the numbers from 0 to n which are Bitwise AND of a binary of n.Let’s take an example to understand the concept better.Input : N = 4. Output : 0 4 Explanation : 0 & 4 = 0 1 & 4 = 0 2 & 4 = 0 3 & 4 = 0 4 & 4 = 4. Input : N = 6 Output : 0, 2, 4, 6To solve this problem, we need to use bitwise operators. Using these we will find the required subsets. We ... Read More
679 Views
In this problem, we are given two nodes of a binary search tree. And we have to print all the values in the range of k1 to k2 that occur in the tree. That is we have to print all the values that are greater than k1 and smaller than k2. And we have to print all these keys in increasing order of their values.Binary Search Tree is a tree which follows these 3 properties −The left subtree has nodes with values lesser than the node’s value.The right subtree has a node with values greater than the node’s value.A subtree’s ... Read More