Abhinaw TripathiJun 17, 20161 min readArrayList Class Collection JavaArrayList Class An ArrayList is like an array, which can grow in memory dynamically.Memory is dynamically allotted and re-allotted to...
Abhinaw TripathiMay 25, 20161 min readAmazon Interview Question: Assume you have a method isSubstring which checks if one word is a substrLet say you have two string s1 and s2 ,write code to check if s2 is a rotation of s1 using only one call to isSubstring(eg. "WaterBottle"...
Abhinaw TripathiMay 25, 20161 min readVery Common Problem on Matrix,if an element in an MXN matrix is 0,its entire row and column are set Solution: public void setZero(int[][] matrix) { boolean[] row= new boolean[matrix.length]; boolean[] row= new...
Abhinaw TripathiMay 25, 20161 min readWrite a method to rotate the image by 90 degree.(In place operation is required).Let say you have an image represented by an NXN matrix where each pixel in the image is 4 byte.So rotate this image in place by 90...
Abhinaw TripathiMay 25, 20161 min readWrite a method to perform basic string compression eg. aabcccccaaa.Should become the ouput a2b1c5a3.Bad Solution: public String compressBad(String str) { String mystr= ""; char last=str.charAt(0); int count = 1; for(int i=1; i<...
Abhinaw TripathiMay 25, 20161 min readWrite a method to replace all spaces with %20 in a String.(Note-Perform in place operation only.)public void replaceSpaces(Char[] str, int length) { int spaceCount=0; int newLength,i; for(i=0;i<lenght;i++) { if(str[i] == ' ') {...
Abhinaw TripathiMay 25, 20161 min readHow will you check,given two strings are permutation of the other.Example: "god" permutation will be "dog" Solution: public String sort(String s) { char[] content = s.toCharArray();...
Abhinaw TripathiMay 25, 20161 min readProgramming Questions on String and its Best Solution with its complexityQuestion: Write an algorithm to find if a string has all unique characters.what if you cannot use additional data-structure?. Solution: i...