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

SDE - 1

Directi
upvote
share-icon
1 rounds | 3 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 6 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: Campus
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
Online Coding Test
Duration90 minutes
Interview date10 Nov 2015
Coding problem3

3 coding questions were given.

1. Longest alternating subsequence

Moderate
15m average time
85% success
0/80
Asked in companies
BarclaysAmazonGoogle

You are given an array ‘ARR’ of integers. Your task is to find the length of the longest alternating subsequence.

Note:
A sequence a1, a2, .... an is called an alternating sequence if its elements satisfy one of the following relations : a1 < a2 > a3 < a4 > a5..... or  a1 > a2 < a3 > a4 < a5.
For example:
'ARR' = {3, 10, 1, 2, 30}, the longest alternating subsequence for this array can be {3, 10, 1, 30} or {3, 10, 2, 30}. Therefore, the answer will be 4.
Problem approach

This problem can be solved using dynamic programming.
Let A is given array of length n of integers. We define a 2D array las[n][2] such that las[i][0] contains longest alternating subsequence ending at index i and last element is greater than its previous element and las[i][1] contains longest alternating subsequence ending at index i and last element is smaller than its previous element, then we have following recurrence relation between them, 
las[i][0] = Length of the longest alternating subsequence ending at index i and last element is greater than its previous element
las[i][1] = Length of the longest alternating subsequence ending at index i and last element is smaller than its previous element
Recursive Formulation:
las[i][0] = max (las[i][0], las[j][1] + 1); 
for all j < i and A[j] < A[i] 
las[i][1] = max (las[i][1], las[j][0] + 1); 
for all j < i and A[j] > A[i]
Time Complexity: O(n2) 
Auxiliary Space: O(n)

Try solving now

2. Maximum Sum Subarray

Moderate
25m average time
75% success
0/80
Asked in companies
Paytm (One97 Communications Limited)AmazonSnapdeal

Given an array of numbers, find the maximum sum of any contiguous subarray of the array.


For example, given the array [34, -50, 42, 14, -5, 86], the maximum sum would be 137, since we would take elements 42, 14, -5, and 86.


Given the array [-5, -1, -8, -9], the maximum sum would be -1.


Follow up: Do this in O(N) time.

Problem approach

The direct approach to solve this problem is to run two for loops and for every subarray check if it is the maximum sum possible. 
Time complexity: O(N^2), Where N is the size of the array.
Space complexity: O(1)
The efficient approach is to use Kadane's algorithm. It calculates the maximum sum subarray ending at a particular index by using the maximum sum subarray ending at the previous position. 
Steps : 
Declare two variables : currSum which stores maximum sum ending here and maxSum which stores maximum sum so far.
Initialize currSum = 0 and maxSum = INT_MIN.
Now, traverse the array and add the value of the current element to currSum and check : 
1. If currSum > maxSum, update maxSum equals to currSum.
2. If currSum < 0, make currSum equal to zero.
Finally, print the value of maxSum.

Try solving now

3. Implement a specialStack class which should support O(1) push O(1) pop and should return minimum element in the stack in O(1) time

Moderate
15m average time
85% success
0/80
Asked in companies
AmazonIntuitMorgan Stanley

Create a stack data structure that allows operations such as push (adding an element), pop (removing the top element), top (retrieving the top element), and also provides a way to retrieve the minimum element in constant time.


Implement the following public functions :

1. push(data) :
This function should take one argument of type integer. It pushes the element into the stack and returns nothing.

2. pop() :
It pops the element from the top of the stack and returns nothing.

3. top() :
It returns the element being kept at the top of the stack.

4.  getMin() :
It returns the smallest element present in the stack.
Operations Performed on the Stack:
Query-1(Denoted by an integer 1): Pushes integer data to the stack. (push function)

Query-2(Denoted by an integer 2): Pops the data kept at the top of the stack. (pop function)

Query-3(Denoted by an integer 3): Fetches and returns the data being kept at the top of the stack. (top function)

Query-4(Denoted by an integer 4): Returns the smallest element present in the stack. (getMin() function)
Problem approach

Two stacks can be used to implement a min Stack. One stack can be used to store the actual stack elements and the other auxiliary stack is used to store minimum values. The top element of the auxiliary stack will always store the minimum at that point of time. Let us see how push() and pop() operations work.
Push(int x) 
1) push x to the original stack (the stack with actual elements) 
2) compare x with the top element of the auxiliary stack. Let the top element be y. 
…..a) If x < y then push x to the auxiliary stack. 
…..b) If x > y then push y to the auxiliary stack.
int Pop() 
1) pop the top element from the auxiliary stack. This is necessary to update the auxiliary stack. 
2) pop the top element from the original stack and return it.
int getMin() 
1) Return the top element of the auxiliary stack.

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

Which array operation has O(n) worst-case time complexity?

Choose another skill to practice
Similar interview experiences
company logo
SDE - 1
3 rounds | 10 problems
Interviewed by Directi
669 views
0 comments
0 upvotes
company logo
SDE - 1
2 rounds | 4 problems
Interviewed by Directi
0 views
0 comments
0 upvotes
company logo
SDE - 1
4 rounds | 7 problems
Interviewed by Directi
690 views
0 comments
0 upvotes
company logo
SDE - 1
3 rounds | 4 problems
Interviewed by Directi
0 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
SDE - 1
5 rounds | 12 problems
Interviewed by Amazon
108663 views
24 comments
0 upvotes
company logo
SDE - 1
4 rounds | 5 problems
Interviewed by Microsoft
52874 views
5 comments
0 upvotes
company logo
SDE - 1
3 rounds | 7 problems
Interviewed by Amazon
32563 views
6 comments
0 upvotes