Jeevan Rex
581 followers -

581 followers
Jeevan's posts
Post has attachment
Post has attachment
Level Order Traversal in a Binary Tree from Bottom to Top
public void LevelOrderReverse()    {         System.out.println(LevelOrderReverse(this));     }     private String LevelOrderReverse(BinarySearchTree T)    {         StringBuffer sb = new StringBuffer();         if(T!=null)    {             Queue<Binary...﻿
Post has attachment
Amazon Question on Array Searching
Given an array, next element is either +1 or -1 of previous element then find any number k ? Example 1: Input: 4 5 4 5 6 7 8 9 8 9 10 11 k = 8 Output = 6 Example 2: Input: 11 10 9 8 7 6 5 4 5 6 7 8 9 10 11 k = 4 Output = 7     public int getIndex(int elemen...﻿
Post has attachment
Bucket Sort
Amazon Question: Given an array with 3 distinct elements, sort the elements in O(n) complexity Input: 1,3,1,2,3,1,2,2,3 Output: 1, 1, 1, 2, 2, 2, 3, 3, 3 import java.util.ArrayList; public class BucketSort {     ArrayList > bucket;     private int count;   ...﻿
Post has attachment
Amazon Question: Print Last N nodes of Linked List in reverse
Given a singly linked list's head and an integer N, print last N nodes of the list in reverse order. Example: List = 1->2->3->4->5->6->7->8 N = 3 Output = 8, 7, 6,     public void printRev(int count)    { // count = N         temp = count; // this here is t...﻿
Post has shared content
Post has attachment
Find if a Tree is a Binary Search Tree
public boolean isBinarySearchTree() { return isBinarySearchTree(this, -9999, 99999); } public boolean isBinarySearchTree(BinarySearchTree T, int min, int max) { if(T==null)return true; if(T.data>min && T.data<max  && isBinarySearchTree(T.left, min, T.data) ...﻿
Post has attachment
Find Maximum Sum of a SubArray
Example Input: -1,2,6,4,-4,-5,56,78,-2,9 Desired Output: 134      public int MaxSumOfSubArray(int... input)    {         int size = input.length;         int max = 0;         boolean isIn = false;         int current_sum = 0;         int previous = -1;     ...﻿
Post has attachment
Rotate a 2D array
public int[] rotate(int count, int... input)    {         for(int i=0; i<count; i++)    {             input = rotate(input);         }         return input;     }     private int[] rotate(int... input)    {         int s =  input.length-1;         int[]...﻿
Post has attachment