Developer I Interview Questions | Glassdoor.co.in

Developer I Interview Questions

208

Developer i interview questions shared by candidates

Top Interview Questions

Sort: RelevancePopular Date

Find the longest palindrome in a string

3 Answers

O(N^2) solution in java: //Now implement the improved method public static String LongestPalindromeImprove(String in) { char[] input = in.toCharArray(); int longestStart = 0; int longestEnd = 0;//we also need global start/end to keep track of the current best as we process //now the key is to scan from mid to both ends for(int mid=0; mid=0 && rightlongestEnd-longestStart)//the longer is found! { longestStart = left; longestEnd = right; } } left--; right++;//sorry added in wrong place, should be in either case per mid choice } //well for even case we need replicate the previous code by making one change left = mid; right = mid+1;//for example 123321 when we choose 33 as mid while(left>=0 && rightlongestEnd-longestStart)//the longer is found! { longestStart = left; longestEnd = right; } } left--; right++; } //do not forget to increase right and decresea left!!! } //after the loop we return return in.substring(longestStart, longestEnd+1); } I also made a demo video to show the whole process to solve this problem with a comparison naive (O(N^3)) method and a test case at http://youtu.be/UhJCXiLSKv0

Check out the nice C code.. http://justprogrammng.blogspot.com/2012/05/find-longest-palindrome-in-string-onn-c.html

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package towerofhanoi; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; /** * * @author sanal */ public class PalindromeEx { public boolean isPalindrome(String str){ char[] chars = str.toCharArray(); int left = 0; int right = chars.length-1; int mid = chars.length/2; for(left=0;left

You've a singly linked list where every node in the list has a field "random" which points to other node in the same list. Write a function to clone this list (create a new copy of the same). Don't use extra space (just the pointer variables are fine).

3 Answers

Prove that limit theta tends to zero sin(theta) / (theta) tends to one?

3 Answers

Determine the anagrams of a word in a file

1 Answer

Describe, in as much detail as possible, everything that happens on a Linux machine from the point when you hit the enter key after typing "./a.out" to the moment when "Hello World!" gets printed on the screen.

1 Answer

Basically Related to Data Structure and Algorithm.

1 Answer

Size of market of used diapers in India.

1 Answer

Some other standard questions: 1. Given a BST and a range, print all the numbers that comes in that range. Ex: the function will be something like: print(node * head, int x, int y); It has to print all numbers within the rage x&y 2. Print max height (level) of a binary search tree. 3. Given an array of integers, determine the sub array which makes max sum. 4. Find LCA of the binary search tree.

1 Answer

Imagine there are n cities (say c1, c2....cn) connected circularly and each of them has a petrol bunk (say p1,p2...pn). The distance between each cities are d1, d2...dn. Here 1unit of petrol will be used to travel 1unit of distance. You can start from any city so that you can go through all of them and reach the same location (city). Find from where we've to begin the navigation. FOR EXAMPLE: c1-->c2-->c3-->c1 p1 has 2ltr p2 has 10ltr p3 has 4ltr and the distance between each cities: c1<-->c2: 3 c2<-->c3: 2 c3<-->c1: 8 Here we've to start at c2 in-order to come back again to the same place. Explain the logic to find whether u can come back to the same location. Find where to start. Write a program for the same. Write test cases for the same.

1 Answer

Write a program to iterate through a 2D grid in a spiral way. Since I can't attach images here, I'll explain it using an array. Imagine you've a nxm matrix of bytes. you've iterate through it in a spiral way. It means, iterate the first row (left to right), then iterate through the right most column (top-bottom) then iterate the bottom most row (right-left) until you reach the center of the matrix. Hope its clear now.

1 Answer
110 of 208 Interview Questions