DSA Interview asked questions 🫡#interviewquestions #datastructures #algorithms #dsa #jobs

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Create a stack
Create a array
Put element one by one if (stack .contain(current elemnt )then add in array else add in stack


Return the array

DarkoGaming
Автор

I think create another array and store frequency once loop is completed then count freq, which is easy probelm

MohammedHasmi
Автор

If we use Set so
Time complexity :- O(n)
Space complexity :- O(n)

AmanSirENGINEER
Автор

a = [1, 2, 3, 4, 5, 6, 5, 7, 7, 8]
b = sorted(a)
c = []
for index, i in enumerate(b[:-1]):
if i == b[index + 1] and i not in c:
c.append(i)
if not c:
print(-1)
else:
print(c)

dakshbhardwaj
Автор

We need to check if count > 1 for each element if it is greater then return the number

tuljarammeghana
Автор

Create a vector for calculating requency asign each frequency as 0 after that make one more vector to store duplicates then run a loop to add frequency in the vector after that check with another loop if frequency is more than 1 pushback element in duplicate vector at last return it

travelbrain
Автор

First find greatest element of array
create vector of that size
mark their count in that vector .
That create answer array and return
Tc 0(n) sc o(n)

interestingduniya
Автор

Sorting gives as O(n log n) right...how come, O(n) then..

Manoj
Автор

Use for loop traversing compare current element with next element use count variable to keep track of each elements count check for the condition count >1 it will print the duplicate elements
Time complexity o(n)
Space complexity o(1)

bhushanp
Автор

Simply use frequency array and then iterate over array for finding duplicates, that's all. TC - O(N), SC-O(N).

samarshelley
Автор

we can do it by making frequency array

ashu.abhi
Автор

sort the array and use temp var and store the value

Adithyan-zt
Автор

Use cycle sort for time O(N) and space O(1)

anshulthakur
Автор

No need to sort .
Use an auxiliary array for frequency of array elements

SumanRout-vtrn
Автор

In java.
• Sort the Array
• Use a Stack
• Maintain an Array and Count
• Keep the Size of an array equal to count
• Check peek and the upcoming element if they are equal store it in an Array and update the count
• At the end after iterating the loop return the Array.

Time Complexity- O(n)
Space Complexity- O(n)

ayushroy
Автор

use frq ary and count 1 any difference than 1 will give duplicate

League
Автор

void checkDuplicate(int marks[], int size){
int temp = 0;
for(int i = 0; i<size; i++){
for(int j = i+1; j<size; j++){
if(marks[i] == marks[j]){
temp = marks[i];
printf("%d ", temp);
}
}
}
};

laxmanbaisoya
Автор

Ek vector lelo jisme frequency store kardo
Baad me check katlo us frequency array me
Jis ka frequency== 2 hai wahi duplicate hai
Agr aisa kuch na mile toh return -1

rupamghosh
Автор

Sorting use karke time complexity o(n logn) hogi

mansimehta
Автор

Sort & then one loop very simple question that i have ever seen my life

Tundak_bhak
join shbcf.ru