Technical blog and complete tutorial on popular company interview questions with detailed solution and Java program on Data structure, Algorithms, Time and space complexity, Core Java, Advanced Java, Design pattern, Database, Recursion, Backtracking, Binary Tree, Linked list, Stack, Queue, String, Arrays etc asked in companies like Google, Amazon, Microsoft, Facebook, Apple etc. for beginners and professionals.
Sunday, 19 February 2017
Saturday, 18 February 2017
Check whether Binary Tree is foldable or not.
Given a binary tree, Check if tree can be folded or not?Java Program to Check whether Tree is foldable.
Check whether given binary tree can be folded or not.
Lets see what is the input and expected output for better understanding on Foldable Binary Tree.
Friday, 17 February 2017
Print Fibonacci series using Recursive approach in Java
Java Program to Print Fibonacci Series upto K Number.
In this post we will see how to Print Fibonacci series using Recursive approach in Java.
Example:
Java program to print fibonacci series up to a given number k.
Input = 5 Output = 0, 1, 1, 2, 3
Input = 2
Output = 0, 1
Input = 7
Output = 0, 1, 1, 2, 3, 5, 8
Print Fibonacci series using Iterative approach in Java
Java Program to Print Fibonacci Series upto K Number.
In this post we will see how to Print Fibonacci series using Iterative approach in Java.
Example:
Java program to print fibonacci series up to a given number k.
Input = 5 Output = 0, 1, 1, 2, 3
Input = 2
Output = 0, 1
Input = 7
Output = 0, 1, 1, 2, 3, 5, 8
Thursday, 16 February 2017
Fibonacci series Iterative and Recursive program in Java
Java Program to print Fibonacci series. OR
Java Program to Print Fibonacci Series upto K Number. OR
Iterative Program to print Fibonacci series. OR
Recursive Program to print Fibonacci series.
What is Fibonacci Series?
Fibonacci series is series of natural number where next number is equivalent to the sum of previous two number.
Example:
Java program to print fibonacci series up to a given number k.
Input = 5 Output = 0, 1, 1, 2, 3
Input = 2
Output = 0, 1
Input = 7
Output = 0, 1, 1, 2, 3, 5, 8
Tuesday, 7 February 2017
Check if two nodes are cousins in a Binary Tree
Given two nodes in a binary tree, check if they are cousins.
Given the binary Tree and the two nodes say ‘p’ and ‘q’, determine whether the two nodes are cousins of each other or not.
Two nodes are cousins if,
- They are not siblings (Children of same parent).
- They are on the same level.
Lets see few example for better understanding on when two nodes are said to be cousin of each other in Binary Tree.