-
Recent Posts
Archives
calendar
December 2025 M T W T F S S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Categories
Meta
Tag Cloud
Tag Archives: coding practice
check if a tree is a bst
int inorderCheck( TreeNode *root, int *last ) { if( root == NULL ) { *last = INT_MIN; return 1; } int left = inorderCheck( root->left, last ); if( root->data > *last && *last != null ) { *last = root->data; … Continue reading
given in-order and pre-order, re-construct a tree
Here is my code : // In-order traversal : c b f d g a e (Left, Root, Right)// Pre-order traversal : a b c d f g e. (Root, left, right)//// static int rootIdx = 0; public Node … Continue reading
sort a linkedlist in place
hint : bubble sort would be the most simple in place one
amazon set 8
Q1: A binary search tree is given by 2 nodes interchanged, find the 2 nodes. my sol : just in-order traveral the tree, it should be ascending sequence. since there are 2 nodes swapped, scan the sequence, find 2 nodes … Continue reading
serialize and deserialize a tree
serialize, ie, convert the object to a byte stream to transfer it through networking, de-seralize, re-construct the object by give output stream. here is the implementation serialize : public static void serialize( OutputStream out, Node node ){ if( node == … Continue reading
amazon set 1
Question 3: There is a N*N integer matrix Arr[N][N]. From the row r and column c, we can go to any of the following three indices: I. Arr[ r+1 ][ c-1 ] (valid only if c-1>=0) II. Arr[ … Continue reading
amazon set 1 answer
amazon set 1 Q1: a sorted array, left rotation r times, find the r in least possible times. sol 1. scan the array, find the min—o(n) sol 2. binary search int findR( int[] arr, int left, int right ) { … Continue reading
amazon set 1
Question 1: There is a binary tree of size N. All nodes are numbered between 1-N(inclusive). There is a N*N integer matrix Arr[N][N], all elements are initialized to zero. So for all the nodes A and B, put Arr[A][B] … Continue reading
3sum issue
public class Solution { public ArrayList<ArrayList<Integer>> threeSum(int[] num) { // Start typing your Java solution below // DO NOT write main() function ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); if( num == null || num.length == 0 ) { return result; } … Continue reading
javascript bind
Method = ( function() { return { bind : function( method, context ) { var argCopy = []; for( i = 2; i arguments.length; i++ ) { argCopy.push( arguments[i] ); } method.apply( context, argCopy ); } }; } )(); Package … Continue reading