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 2149 of 3366
221 Views
In this problem, we are given a tree. And we have to print all the levels with even number of nodes and odd number of nodes in it.Let’s take an example to understand the concept betterOutput −Levels with odd number of nodes: 1, 3, 4 Levels with even number of nodes: 2Explanation − The first level has only 1 element(odd), 2nd level contains two elements(even), 3rd level contains 3 elements(odd) and 4th level contains 1 element(even).Now, to solve this problem. We need to find the count of nodes at each level and print the even-odd levels accordingly.We will follow the ... Read More
221 Views
In this problem, we are given an array of unique integers. And we have to return all pairs of integers(positive and negative integers) that are present in the array.Let’s take an example to understand the problem better −Input: array = {1 , 4 , 7 , -1, 2, 5, -7} Output: -11 -33An easy way to solve the problem is by using two loops and find the positive-negative pairs. But this solution will be a complex one and will have time complexity of the order n2 where n is the size of the array.But, we have to find a more ... Read More
316 Views
In this problem, we are given a string of size n. And we have to print all possible palindromic permutation that can be generated using the characters of the string in alphabetical order. If palindrome is not created using the string print ‘-1’.Let’s take an example to understand the topic better −Input: string = “abcba” Output : abcba bacbaNow, to solve this we need to find all the palindromes possible and then arrange them in alphabetical order(lexicographical order). Or another way could be finding the lexicographically first palindrome that is made from the string. Then find the sequentially next palindrome ... Read More
206 Views
In this problem, we are given a Binary tree and a sum S. And we have to find the path starting from root to any node of the tree, which gives the sum equal to the given sum.InputSum = 14 Output : path : 4 10 4 3 7To find the solution to this problem, we need to find the preorder traversal of the binary tree. And then find the path that adds up to the given sum.Example Live Demo#include using namespace std; struct Node{ int key; struct Node *left, *right; }; Node* insertNode(int key){ Node* temp = ... Read More
181 Views
In this problem, we are given an array of n unique integers. And we have to find the sum of two integers of the array which has the maximum frequency. The problem has multiple solutions and you need to find them all.Input : array = { 1, 12, 5, 7, 9, 11} Output : 16 12Explanation − sum 16 and 12 occur two times.5 + 11 = 16 & 7 + 9 = 16 1 + 11 = 12 & 5 + 7 = 12Now to solve this problem, our approach to the problem is checking the occurrence every sum ... Read More
241 Views
In this problem, we are given a sorted array of numbers and we need to find the triplets with are in the form of arithmetic progression.An arithmetic progression is a series of numbers in which the difference between consecutive terms is the same.Let’s take an example to understand the problem better −Input : array = {2 , 5 , 7, 8 , 9 , 10} Output : 2 5 8 5 7 9 7 8 9 8 9 10To solve this problem, a simple solution would be running three loops and checking all triplets if they are in AP. but ... Read More
291 Views
In this problem, we are given an array of unique integers and a sum. And we have to find the triplets which can form the same sum.Let's take an example to solve the problem −Input : array = {0 , 2 , -1 , 1, -2} Sum = 1 Output : 1 2 -2 0 2 -1To solve this problem, we will be finding all the triplets that provide the sum. A simple approach will be using three loops and finding the sum of the elements and return the adequate triplet.Example Live Demo#include using namespace std; void Triplets(int arr[], int ... Read More
149 Views
More is a command to view (but not modify) the contents of a text file, one screen at a time. It is available on Unix and Unix-like systems, DOS, OS/2, and Microsoft Windows. Programs of this sort are called pagers. More is a very basic pager, originally allowing only forward navigation through a file, though newer implementations which allows for limited backward movement.The basics of more command should be like this –$ more /var/log/dkpg.logThe sample output should be like this –2016-12-02 11:30:45 startup archives unpack 2016-12-02 11:30:45 install python-ptyprocess:all 0.5-1 2016-12-02 11:30:45 status half-installed python-ptyprocess:all 0.5-1 2016-12-02 11:30:45 status ... Read More
363 Views
IntConsumer interface is a functional interface from java.util.function package in Java 8. This interface accepts a single int-valued argument as input but doesn't produce any output. Since it is a functional interface, it can be used as an assignment target for a lambda expression or method reference. It contains one abstract method: accept() and one default method: andThen().Syntax@FunctionalInterface public interface IntConsumer { void accept(int value); }Example of Lambda Expressionimport java.util.function.IntConsumer; public class IntConsumerTest1 { public static void main(String[] args) { IntConsumer displayNextInt = i -> System.out.println("Next Int Value: " + (i+1)); // lambda IntConsumer displaySquare = ... Read More
2K+ Views
The "this" and "super" references within a lambda expression are the same as in the enclosing context. Since the lambda expression doesn't define a new scope, "this" keyword within a lambda expression signifies "this" parameter of a method where the lambda expression is residing.In the below example, this.toString() calls the toString() method of the LambdaTest object but not the toString() method of the Operate instance.Example@FunctionalInterface interface Operate { int func(int num1, int num2); public String toString(); } public class LambdaTest { public static void main(String[] args) { LambdaTest test = new LambdaTest(); test.getResult(); } ... Read More