ShareChat interview experience Real time questions & tips from candidates to crack your interview

SDE - 2

ShareChat
upvote
share-icon
1 rounds | 2 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 4 months
Topics: Data Structures, Algorithms, System Design, Aptitude, OOPS
Tip
Tip

Tip 1 : Must do Previously asked Interview as well as Online Test Questions.
Tip 2 : Go through all the previous interview experiences from Codestudio and Leetcode.
Tip 3 : Do at-least 2 good projects and you must know every bit of them.

Application process
Where: Referral
Eligibility: Above 7 CGPA
Resume Tip
Resume tip

Tip 1 : Have at-least 2 good projects explained in short with all important points covered.
Tip 2 : Every skill must be mentioned.
Tip 3 : Focus on skills, projects and experiences more.

Interview rounds

01
Round
Medium
Video Call
Duration45 minutes
Interview date16 Feb 2021
Coding problem2

Technical Interview round with questions on DSA.
Tip : Do variants of Binary Search.

1. Find Square root of an integer

Easy
20m average time
80% success
0/40
Asked in companies
OraclePharmEasyShareChat

You are given an integer ‘A’. Your task is to find the greatest non-negative integer whose square is less than or equal to ‘A’.

Square of a number is the product of the number with itself. For e.g. square of 3 is 9.

Problem approach

The Simple Approach is to find the floor of the square root, try with all-natural numbers starting from 1. Continue incrementing the number until the square of that number is greater than the given number.


Algorithm : 
1. Create a variable (counter) i and take care of some base cases, i.e when the given number is 0 or 1.
2. Run a loop until i*i <= n , where n is the given number. Increment i by 1.
3. The floor of the square root of the number is i – 1
 

Time Complexity: O(√ n). 
 

The Better Approach would be to use Binary Search. The idea is to find the largest integer i whose square is less than or equal to the given number. The values of i * i is monotonically increasing, so the problem can be solved using binary search. 
 

Algorithm : 
1. Take care of some base cases, i.e when the given number is 0 or 1.
2. Create some variables, lowerbound l = 0, upperbound r = n, where n is the given number, mid and ans to store the answer.
3. Run a loop until l <= r , the search space vanishes
4. Check if the square of mid (mid = (l + r)/2 ) is less than or equal to n, If yes then search for a larger value in second half of search space, i.e l = mid + 1, update ans = mid
5. Else if the square of mid is more than n then search for a smaller value in first half of search space, i.e r = mid – 1
6. Print the value of answer.
 

Time Complexity : O(log(n))

Try solving now

2. Find the minimum element in a sorted and rotated array

Moderate
10m average time
90% success
0/80
Asked in companies
OlaAmazonMorgan Stanley

You are given an array 'arr' of size 'n' having unique elements that has been sorted in ascending order and rotated between 1 and 'n' times which is unknown.


The rotation involves shifting every element to the right, with the last element moving to the first position. For example, if 'arr' = [1, 2, 3, 4] was rotated one time, it would become [4, 1, 2, 3].


Your task is to find the minimum number in this array.


Note :
All the elements in the array are distinct. 


Example :
Input: arr = [3,4,5,1,2]

Output: 1

Explanation: The original array was [1,2,3,4,5] and it was rotated 3 times.


Problem approach

The brute force solution is to traverse the entire array and find the minimum. Time Complexity : O(N)


The efficient approach is to use Binary Search. The following pattern can be observed : 
 

• The minimum element is the only element whose previous is greater than it. If there is no previous element, then there is no rotation (the first element is minimum). We check this condition for the middle element by comparing it with (mid-1)’th and (mid+1)’th elements.
 

• If the minimum element is not at the middle (neither mid nor mid + 1), then the minimum element lies in either the left half or right half. 
1. If the middle element is smaller than the last element, then the minimum element lies in the left half
2. Else minimum element lies in the right half.
 

 

Pseudocode:

Low = 0
High = n-1
findMin(arr,low, high)
{
	while(low < high)
	{
		mid = low + (high - low)/2
		if (arr[mid] == arr[high])
			high--
		else if(arr[mid] > arr[high])
			low = mid + 1
		else
			high = mid
	}
	return arr[high]
}
Try solving now

Here's your problem of the day

Solving this problem will increase your chance to get selected in this company

Skill covered: Programming

What is recursion?

Choose another skill to practice
Similar interview experiences
company logo
SDE - 2
4 rounds | 5 problems
Interviewed by ShareChat
1401 views
0 comments
0 upvotes
company logo
Technical Lead
4 rounds | 4 problems
Interviewed by ShareChat
889 views
0 comments
0 upvotes
company logo
SDE - 2
3 rounds | 5 problems
Interviewed by ShareChat
1252 views
0 comments
0 upvotes
company logo
SDE - 2
4 rounds | 4 problems
Interviewed by ShareChat
1318 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
SDE - 2
5 rounds | 12 problems
Interviewed by Walmart
29570 views
8 comments
0 upvotes
company logo
SDE - 2
3 rounds | 5 problems
Interviewed by Amazon
6678 views
1 comments
0 upvotes
company logo
SDE - 2
6 rounds | 8 problems
Interviewed by Amazon
5176 views
0 comments
0 upvotes