Site icon NgDeveloper

[2021] Top 10 Data Structures Algorithms (DSA) Interview Questions and Answers

1. How do you validate the Bracket expressions are valid ?

We can use stack to valildate the valid bracket expressions.

For example:

Try yourself the for the Solution with stack’s basic push and pop, if you are not able to bring the solution, then checkout the sample program here.

2. How do you split the array for the given size ?

Basically we want to divide the array into multiple pieces based on the given size. Inputs and outputs are below:

Here is the javascript program to achieve the same results:

let inputArray = [1,2,3,4,5,6,7,8,9];
let splitCount = 3;
let outputArray = [];
for (let i=0;i<inputArray.length;i+=splitCount){	
	let tempArray = [];
	for(let j=i;j<splitCount+i;j++){
		tempArray.push(inputArray[j]);		
	}
	outputArray.push(tempArray);
}
console.log(outputArray);

3. write a program for Pig Latin logic

Rules/requirements for pig latin is below,

Solution is going to be with simple if and for loop only, Try yourself first, if not able to get the solution, then do checkout here.

4. Write a program for fizzbuzz logic

Fizzbuss rules:

Solution is going to be with simple if and loops only, Try yourself first, if not able to get the solution, then do checkout here.

5. Write a program for Palindrome logic

Logic:
Given Number/String should be equal with the Reversed of the given Number/String.

Examples:

You need to basically derive the two different logics for both numbers and strings. Try yourself first, then check the solution code here.

6. How do you print all the possible combinations of a 3 digit number / character ?

Not worrying about the best approach, then its just a matter of nested for loops. You can find the solution here.

7. Given number is prime number or not.

Here is the prime number check logic:

Logic:

Try yourself for the solution first, then check the solution here.

8. Write a program to print the pyramid numbers

It is again a matter of few loops and I can also share you the logic overview below, try with the same / check the solution here

9. Reverse a string using stack (not with the reverse() inbuilt method)

The idea is to push everything into stack first, then pop everything and append to get the reverse string.

Try yourself first, then checkout this solution here.

10. Sum of the first 5 prime numbers

You can find the prime number finding logic here.

Do additional logic to filter only first few either with simple temp variable / add the first few to list and sum the result of the list.

11. How do you identify the first repeated vowels in the given string ?

Try the solution yourself and put your solution in the comments below to get published here, all the solutions will be published here.

Input: Ngdeveloper is the programming blog
Output Expected: e

Input: saveji is best coupons website
Output Expected: i

12. Rotate the string with the given times right size

Try the solution yourself and put your solution in the comments below to get published here, all the solutions will be published here.

Input: Ngdeveloper, 3
Output: perNgdevelo

13. How do you count the vowels in the given string using Recursions ?

This is easy problem for one who is having good understanding about the stack and recursions. If you are one among them, then try the solution and paste it in our below comment box, if not reached the solution then do checkout our solution here.

Exit mobile version