Java Interview Question Part 2 Implementation | Sorting of Array Depending on Frequency of Elements

preview_player
Показать описание
You are given any array of length n.
You have to sort the array elements in descending order of their frequency.
Use of Collections is not allowed

E.g :
Input : [4,3,1,6,4,3,6,4]
Output : [4,4,4,3,3,6,6,1]

Follow on Facebook:

Subscribe to our other channel:
Telusko Hindi :
Рекомендации по теме
Комментарии
Автор

Perfect explanation! I see myself sitting in the next interview and will have a chance this time - just by your help! Thanks a lot!!

health.upgradedbyscience.
Автор

need more videos like these...thanks Telusko!

sagarmeena
Автор

where is the part 1 please give me the link

shivam
Автор

We can use hashmap here instead of 2-D array

dheerajsahu
Автор

Hi Navin,
When element is added for first time you are saying default .but where are you mentioning it?

narendra
Автор

Hallo Navin,
int[] array = {2, 4, 2, 2, 3, 6, 9, 9, 9, 9};

int element = 0;
int count = 0;

for( int i = 0 ; i < array.length; i++) {

int tempElement = array[i];
int tempCount= 0;
for(int j = 0; j < array.length; j++) {
if(array[j] == tempElement)
tempCount++;
}
i did up to hear, After that how should i sort them in dependency Bcoz all the frequency values is there in "tempCount++" where should i store them and how should i call them to sort?

I think for this no need of two dimentional "System.out.println(" " + element + "---> " + count);"

praveenbi
Автор

Hi Navin, I like your pet word...."then question arise".

mohammedshafiuddin
Автор

Please make more vedios on java interview questions

AA-dljw
Автор

Flaw in your code: else for step 2 missing 1 line!
else
{
row++;
b[row][0]=arr[i];
b[row][1]=1;
//missing!!!!
}

adikittur
Автор

Could not understand ! we could use hashMap

Adam-gpij
Автор

Hallo Navin, Sorry to say, Seriously i didn't understand what you are saying, And i need clear explanation about frequency of elements sorting in dependency i need to know if possible can you please help me

praveenbi
Автор

Hi sir,
i am tagore. i am not using sort method.

My without sort method code:

int arr1[] = {9, 4, 2, 8, 1};

for(int a = 0; a<arr1.length; a++) {
for(int b=a; b<arr1.length; b++ ) {
if(arr1[a]>arr1[b])
+ arr1[b] - (arr1[a] = arr1[b]);
}
System.out.print(arr1[a] + " ");
}

tagorebanda
Автор

Please try to complete explanation of a problem in one video

sourabhpothula
Автор

Please, there are better approaches than this, you could have used BST or hash

niketkumar
Автор

Hi Naveen,

The kind of explanation you are using to explain the technique is totally not understandable.
May be you should practice teaching before uploading/recording the video

@Naveen

sugyanpatnaik
Автор

First time I'm disappointed with your video.

shahrukh
Автор

Very very poor explanation. Please remove this and put a new video. You're clearly under prepared here.

moin