Sort Characters By Frequency | Sorting | Lambda | Leetcode 451

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 พ.ย. 2024

ความคิดเห็น • 49

  • @naturevinu7886
    @naturevinu7886 9 หลายเดือนก่อน +5

    aap jo story batate ho to lagta he bhai coding to me bhi kar sakta hu or bahot had tar to problme khud hi solve kar pata hu love you sir

  • @aws_handles
    @aws_handles 9 หลายเดือนก่อน +12

    I get relaxed when I see you already have a video on youtube for a problem.

  • @AdityaSharma-sf1yh
    @AdityaSharma-sf1yh ปีที่แล้ว +4

    You are genius, you don't know but you have explained it perfectly and far better than other TH-cam tutors.
    Thank you so much!

  • @hrithikrudra4292
    @hrithikrudra4292 ปีที่แล้ว +5

    Amazing brother....Keep uploading such wow content..

  • @udaytewary3809
    @udaytewary3809 ปีที่แล้ว +1

    Really thankyou bhaiya for making it so easy to understand and also learn new things about comparator from you

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      I am so glad to hear that Uday ❤️❤️❤️

  • @souravjoshi2293
    @souravjoshi2293 ปีที่แล้ว +2

    Thanks a lot man. simple and crystal clear

  • @Ankitkumar-fz3kc
    @Ankitkumar-fz3kc 9 หลายเดือนก่อน +1

    Thanks, I solved it by myself still came here to learn something new and learnt something thanks.

    • @codestorywithMIK
      @codestorywithMIK  9 หลายเดือนก่อน +3

      So glad to know ❤️❤️🙏🙏
      Always note down the things which you are learning in a note book, or note it down somewhere so that you can revisit them later

    • @Ankitkumar-fz3kc
      @Ankitkumar-fz3kc 9 หลายเดือนก่อน +2

      @@codestorywithMIK sir how to take notes and how to revise can you please share some insight regarding this.

    • @FifthArima
      @FifthArima 9 หลายเดือนก่อน +1

      @@Ankitkumar-fz3kc had the same doubt. @codestorywithmik pls share your inputs

    • @codestorywithMIK
      @codestorywithMIK  9 หลายเดือนก่อน +2

      For taking notes,
      What I did was note the important points on a Notebook earlier.
      But I wanted to access it anywhere so I started to make notes online (google doc etc) so that I can access it online from anywhere.
      Make. Google doc dedicated to every topic and keep the notes in those.
      Keep revisiting them time to time

  • @priyamittal8302
    @priyamittal8302 8 หลายเดือนก่อน +1

    Finally understood this concept. thanks a lot!

  • @souradeepghosh9888
    @souradeepghosh9888 9 หลายเดือนก่อน

    Nice explanation bhaiya

  • @wearevacationuncoverers
    @wearevacationuncoverers ปีที่แล้ว

    Keep uploading such amazing contents.

  • @divyanshuaaliwal_
    @divyanshuaaliwal_ 2 หลายเดือนก่อน

    Awsm explanation !

  • @theOmKumar
    @theOmKumar 9 หลายเดือนก่อน +2

    I solved it like this.
    string frequencySort(string s) {
    string ans;
    int freq[128] = {0};
    for(int i = 0; i < s.size(); i++){
    freq[s[i]]++;
    }
    map m;
    for(int i = 0; i < 128; i++){
    m[ freq[i] ] += string(freq[i], (char)i);
    }
    for(auto it = m.rbegin(); it != m.rend(); it++){
    ans += it->second;
    }
    return ans;
    }

  • @varunsheth1003
    @varunsheth1003 ปีที่แล้ว +1

    Amazing brother...

  • @gauravbanerjee2898
    @gauravbanerjee2898 9 หลายเดือนก่อน

    Thanks a lot bhaiya ❤❤

  • @saumyasrivastava5390
    @saumyasrivastava5390 ปีที่แล้ว +3

    Please upload the PQ solution as well. I implemented this but I am unable to think in that direction

    • @souravjoshi2293
      @souravjoshi2293 ปีที่แล้ว +2

      Me too.
      It would be great to have a PQ solution as well for this from you @Interview_DS_Algo
      Thanks in advance

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +6

      Sure. I am on it.
      Give me sometime. I will upload it today only.
      Thanks again for your question and watching my videos

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +4

      Uploaded the Heap(PQ) approach
      Link :th-cam.com/video/HwCYa1_2vkU/w-d-xo.html

    • @aws_handles
      @aws_handles 9 หลายเดือนก่อน

      Thanks a lot@@codestorywithMIK

    • @thekindspill
      @thekindspill 9 หลายเดือนก่อน

      @@codestorywithMIK I was looking for this. Thank you

  • @kumarashutosh-p3n
    @kumarashutosh-p3n 5 หลายเดือนก่อน +1

    unordered_mapm;
    for(auto x:s)
    m[x]++;
    sort(begin(s),end(s),[&](char a, char b){
    return m[a]!=m[b]?m[a]>m[b]:a

  • @ShubhiSrivastava-dc6zk
    @ShubhiSrivastava-dc6zk ปีที่แล้ว

    is code ki space complexity or time complexity explain kr dijiye plz plz

  • @VinayKumar-vm1hg
    @VinayKumar-vm1hg 9 หลายเดือนก่อน

    vec[ch] or we have to take index

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 9 หลายเดือนก่อน

    class Solution {
    public String frequencySort(String str){
    char[]s=str.toCharArray();
    int[]freq=new int[128];
    for(int i=0;i

  • @DevOpskagyaan
    @DevOpskagyaan 9 หลายเดือนก่อน

    Done ❤️

  • @rajeevkumarsingh8719
    @rajeevkumarsingh8719 ปีที่แล้ว +1

    i m confused that how the pair get stored in vector can anyone help. line 9-11

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +3

      Hi Rajeev, let's look at an example to understand this.
      Suppose we have example : "tree"
      Now let's populate : vector vec;
      i = 0, 't', we don't have 't' populated in vector as of now.
      vec = { {'t', 1}}
      i = 1, 'r', we don't have 'r' populated in vector as of now.
      vec = { {'t', 1}, {'r', 1}}
      i = 2, 'e', we don't have 'e' populated in vector as of now.
      vec = { {'t', 1}, {'r', 1}, {'e', 1}}
      Now, for i = 3, 'e', we already have {'e', 1} in our vector
      So, take out frequency of 'e' already present in vector : i.e. freq = 1
      int freq = 1
      Now, we add 1 more to it, because we have got another 'e' at index = 3 and then insert it back to vec (updated value)
      vec = { {'t', 1}, {'r', 1}, {'e', 2}}
      Hope I was able to clear now.
      Thank you for watching

    • @rajeevkumarsingh8719
      @rajeevkumarsingh8719 ปีที่แล้ว +2

      Yeah very helpful

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Glad to know that Rajeev. Thanks

  • @factshubonly
    @factshubonly 9 หลายเดือนก่อน

    ordered map already sorted hota hai usse nhi kar sakte kya?

  • @tech_funda_official
    @tech_funda_official 6 หลายเดือนก่อน

    is solution me kya problem h?
    class Solution {
    public:
    string frequencySort(string s) {
    typedef pair P;
    vector arr(122);
    for (char& i : s) {
    int freq = arr[i].second;
    arr[i] = {i, freq + 1};
    }
    auto lambda = [&](P &p1, P &p2) { return p1.second > p2.second; };
    sort(arr.begin(), arr.end(), lambda);
    string ans = "";
    for (int i = 0; i

  • @prathamdhiman7071
    @prathamdhiman7071 9 หลายเดือนก่อน

    Sir can you also code in java

  • @xboy2374
    @xboy2374 8 หลายเดือนก่อน

    bhaiua run time error aa rhaa 32 test case mai se 29 chle

    • @codestorywithMIK
      @codestorywithMIK  8 หลายเดือนก่อน

      My code seems to be working fine. Can you share your code ?

  • @harshkumar4047
    @harshkumar4047 2 หลายเดือนก่อน

    Mention in the video title only for C++ language, bcz Java valo ko toh kuch samjh hi nhi aya.

    • @harshasshet6755
      @harshasshet6755 2 หลายเดือนก่อน

      bro concept to same hai just language is diferent learn concept and for code ask chatgpt and all fine

    • @harshkumar4047
      @harshkumar4047 2 หลายเดือนก่อน

      @@harshasshet6755 Beta 9:00 minute se jo isne bataya hai voh code based hai (C++ language specific), isme conceptual kuch nhi hai.
      Real conceptual videos irrespective of lang. dekhne hai toh jaa kr Striver dekh munna.