Skip to content

This repository contains all the technical questions that has been asked to me while interviewing different companies with in India.

Notifications You must be signed in to change notification settings

asharn/interview-questions-software-engineer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 

Repository files navigation

This repository will contain all the java, spring, hibernate, mysql, elastic search, thread, related questions.

Java

Spring

Hibernate

http://hibernate.org/orm/documentation/5.4/

Sql

Rest API

Elastic Search

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs.html

Design Pattern

Maven

AWS

Microservice

Docker

Python

Javascript

ReactJS

EXTJS

PUZZLE

MISC

Competitive Programming

  • Find 2nd lagest number in an array? Input: {23,10,34,23,20} -> output: 23
      set arr = [23,10,34,23,20]
      int lengthOfArray = arr.length();
      int max = 0;
      int secondMax = 0;
      for(int i=0;i<lengthOfArray;i++){
      if(arr[i]>max){
      secondMax = max;
      max= arr[i];
      }
    
      s.o.p(secondMax);
    
      }
    
  • Occurance count string = "AAABBCCCDDAACCEE" then ouput : 3A2B3C2D2A2C2E
          public class Main
        {
            public static void main(String[] args) {
    
                String str = "AAABBCCCDDAACCEE";
                int strLength = str.length();
                char ch = str.charAt(0);
                int counter = 0;
                for(int i=0;i<strLength;i++){
                    if(ch == str.charAt(i)){
                        counter=counter+1;
                        continue;
                    } else {
                        System.out.print(counter);
                        System.out.print(ch);
                        counter = 1;
                        ch = str.charAt(i);
                    }
                }
                System.out.print(counter);
                System.out.print(ch);
            }
        }
    
  • all permutation of a string = "ABC" then ouput : ABC, ACB, BAC, BCA, CAB, CBA
  • https://www.onlinegdb.com/Ptod_C-qS
  • https://www.onlinegdb.com/2_k3E2v6H
  • Print the second highest from the given list of integer in java
  • Java Program to Get the middle element of LinkedList in a single iteration.
  • Recursive find fibonacci number?
        public class Test {
    
        //0,1,1,2,3,5,8,13
        public static int fib(int n) {
          if(n==1) {
            return 0;
          }else if(n==2){
            return 1;
          }else {
            return fib(n-1)+fib(n-2);
          }
    
        }
        public static void main(String []args) {
          System.out.println(fib(8));
    
        }
       }
    
  • [Using Steam API genelrate list of string from a comma seperated string]
      String commanSeperated = "ashish,karn,sunil,kumar,anil,verma";
      	List<String> listOfStr = Arrays.stream(commanSeperated.split(",")).collect(Collectors.toList());
    
  • Transform from [0,1,0,1,0,1,1,1,0,0] to [0,0,0,0,0,1,1,1,1,1]
	int[] arr = {0, 1, 0, 1, 0, 1, 1, 0, 1, 1 };
		boolean flagFindOne = true;
		int indexOfOne = -1;
		for (int i = 0; i < arr.length; i++) {
			if (flagFindOne && arr[i] == 1) {
				indexOfOne = i;
				flagFindOne = false;
			} else if (!flagFindOne && arr[i] == 0) {
				int temp = arr[i];
				arr[i] = arr[indexOfOne];
				arr[indexOfOne] = temp;
				i = indexOfOne;
				flagFindOne = true;
			}
		}
        System.out.println(Arrays.toString(arr));
  • Write a java program to get maxing profit by buying and selling a share from a given set of values. If consider buying only once and selling once.
  • You are given an array prices where prices[i] is the price of a given stock on the ith day.

	Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

	Example 1:
	Input: prices = [7,1,5,3,6,4]
	Output: 5
	Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
	Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
	
	Example 2:
	Input: prices = [7,6,4,3,1]
	Output: 0
	Explanation: In this case, no transactions are done and the max profit = 0.

			int stockPrices[] = {7,6,4,3,1};
			int len = stockPrices.length;		
			Map<Integer,Integer> pairs = new HashMap<>();
			for(int i=0;i<len;i++) {
				for(int j=i+1;j<len;j++) {
					if(stockPrices[i] < stockPrices[j] ) {
						if(pairs.get(stockPrices[i]) == null || pairs.get(stockPrices[i]) < stockPrices[j]) {
							pairs.put(stockPrices[i], stockPrices[j]);
						}
					}
				}
			}
			System.out.println(pairs);
			int max = 0;
			for(Entry<Integer, Integer> value:pairs.entrySet()) {
				if(max < (value.getValue() - value.getKey())) {
					max = value.getValue() - value.getKey();
				}
			}
			System.out.println(max);
  • Find forth largest number using stream api.

     	int fourthLargest = Arrays.stream(arr).boxed().sorted(Comparator.reverseOrder()).skip(3).findFirst().get();
     	System.out.print(fourthLargest);
    
  • Find employe list which have lowest salary from the dept.

	name:
	salary:
	dept:
	emp_id

	Map<Integer, Employe> mapOfEmployes
	
  • Find count of string and all char existence
	main(){
		String str = "ashish Karnqweeeqwewqes123645dfsdfa123";
		int arr[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //26 length

		for(int i=0;i<str.lenght;i++){
			if(ascii(str[i]) > 96 && ascii(str[i]) < 122){
				arr[ascii(str[i])-97] =  arr[ascii(str[i])-97] + 1;
			}
		}
		print(isAllCharExists(arr))
		}
	boolean isAllCharExists(int []arr){
	for(int i=0;i<arr.length;i++){
		if(arr[i]==0){
			return false;
		}
	}
	return true;
	}

	boolean displayCharCount(int []arr){
	for(int i=0;i<arr.length;i++){
			print(charValueOf(97+i), " ")
			print(arr[i])
	}
	return true;
	}
  • Reverse word of the sentence. Like "my name is khan" to "ym eman si nahk"
	String str = "my name is khan";
   String[] strArr = str.split(" ");
   for(int i=0;i<strArr.length;i++) {
   	for(int j=strArr[i].length()-1;j>=0;j--) {
   		System.out.print(strArr[i].charAt(j));
   	}
   	System.out.print(" ");
   }	
  • Three best rating from Employee list
	Employee employee = new Employee();
	employee.rating = 5;
	employees.add(employee);
	employee = new Employee();
	employee.rating = 6;
	employees.add(employee);
	List<Employee> collect = employees.stream().sorted((f1, f2) -> Integer.compare(f2.rating, f1.rating)).limit(3).collect(Collectors.toList());
	or 
	List<Employee> collect = employees.stream().sorted(Comparator.comparingLong(Employee::getRating).reversed()).limit(3).collect(Collectors.toList());

	System.out.println(collect);
return items.stream()
     .filter(Objects::nonNull)
     .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));

About

This repository contains all the technical questions that has been asked to me while interviewing different companies with in India.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published