public class count { public static void main(String[]args){ int []arr={1,2,3,4,2,2,3,1}; int []freq=new int[arr.length]; int visited = -1; for(int i=0;i
We have set freq[j] = visited....because we have already updated the count of that element(freq[j]) and we dont want to visit that element again Otherwise same element's frequency will be updated again and again and it wont provide the required result.
i have doubt related that you have print elements and their frequency for unique elements that not visited but what about that elements that stored in freq[j] how they print?
public class count {
public static void main(String[]args){
int []arr={1,2,3,4,2,2,3,1};
int []freq=new int[arr.length];
int visited = -1;
for(int i=0;i
why visited = -1?
very well explained. Thanks, but still i have a confusion on why we have stored visited in arr[j] ??
We have set freq[j] = visited....because we have already updated the count of that element(freq[j]) and we dont want to visit that element again
Otherwise same element's frequency will be updated again and again and it wont provide the required result.
How to do it if time complexity O(N) using brute force
ua-cam.com/video/pzQvKGcze3A/v-deo.html
Checkout this video
@@TechnosageLearning yeah i hve checked out this but the concept of has map isn't thought to us yet so i was asking if there was any other way
what will happen if the give array has value of visited that is "-1"
it will not print(exclude)
i have doubt related that you have print elements and their frequency for unique elements that not visited but what about that elements that stored in freq[j] how they print?
Well explained maam
Well explained
8
2 0 1 1 1 0 3 1
ans=2 4 1 1
code output=2 4 1 0
how can i handle this case
after sorting array
same as the code in the internet
thanks
very Awesome explaination.
Thank you!
which screen recorder u r using??
Default Mac screen capture tool
Well explained mam 👍
Thank you😊