SenseForth AI Research Private Limited.

Date : May - 2020
Mode : Hangout Video for theoretical question & CodeLite for coding 
Interviewer - Ranjit Sah.

1. How do you rate yourself in java?

2. How good are you at data structure and algorithm.

3. What is Generics and why do we use it in collection?

4. Explain your roles and responsibility in the last projects.

5. There are couple of elements stored in doubly linked list, how to find the middle element. This doubly linked list is not the defined data structure in java collection so you can't use collection api. 

6. We have a String str="lovelovexl"
Write java code to return the index of first unique character or return -1 if there is no any unique character in the given string.

Solution:
package string;
import java.util.*;
public class SenseForth {
public static void main(String[] args) {
String str="lovelovexl";
         System.out.println(countChar(str));
}
static int countChar(String str){
        int value=0;
        LinkedHashMap<Character,Integer> hmap=new LinkedHashMap<>();
        for(int i=0;i<str.length();i++){
        char ch=str.charAt(i);
            if(hmap.containsKey(ch)){
               value=hmap.get(ch);
               value++;
                hmap.put(ch,value);
            }else{
                hmap.put(ch,1);
            }
        }
        System.out.println(hmap);
        Set set =hmap.entrySet();
        Iterator it=set.iterator();
        while(it.hasNext()){
        Object obj=it.next();
        Map.Entry entry=(Map.Entry)obj;
            Integer in=(Integer)entry.getValue();
            if(in==1){
               char ch=(Character) entry.getKey();
               return str.indexOf(ch);
            }
        }
        return -1;
    }
}


Output :
{l=3, o=2, v=2, e=2, x=1}
8

Comments

Popular posts from this blog

Mobileum Bangalore Core Java Developer Interview

Xylem bangalore : Senior Java Developer.

Core Java Interview Question's Answers - 2