Pregunta de entrevista de A9.com

1. Finding first non repeated character in an array 2. Linux command to list files containing specific string 3. Mysql query related to Group by Second phone interview 1. create a doubly linked list out of that tree where each node represents sum of all nodes in the same vertical line. 2. Implement search for a sorted rotated array.

Respuestas de entrevistas

Anónimo

6 may 2015

public class Solution { /** *@param A : an integer rotated sorted array *@param target : an integer to be searched *return : an integer */ public int search(int[] A, int target) { // write your code here if(A == null || A.length == 0){ return -1; } int start = 0; int end = A.length - 1; int mid; while(start + 1 < end){ mid = start + (end - start) / 2; if(A[mid] == target){ return mid; } if(A[start] < A[mid]){ if(A[start] <= target && target <= A[mid]){ end = mid; }else{ start = mid; } }else{ if(A[mid] <= target && target <= A[end]){ start = mid; }else{ end = mid; } } } if(A[start] == target){ return start; }else if(A[end] == target){ return end; }else{ return -1; } } }

1

Anónimo

25 oct 2017

1. Finding first non repeated character in an array class FirstNonRepeatedCharacter{ public static void main(String args[]){ Character[] input = {'a'}; if(input.length==1){ System.out.println(input[0]); } else if(input.length>1){ for(int i=0;i

Anónimo

25 oct 2017

1. Finding first non repeated character in an array class FirstNonRepeatedCharacter{ public static void main(String args[]){ Character[] input = {'a','b','c','b','a'}; if(input.length==1){ System.out.println(input[0]); } else if(input.length>1){ Set unique = new LinkedHashSet(); Set duplicates = new LinkedHashSet(); for(int i=0;i

Anónimo

25 oct 2017

Linux command to list files containing specific string grep -l "string" path to directory