1002. Find Common Characters | string manipulation | leetcode daily challenge | DSA | Hindi

Поделиться
HTML-код
  • Опубликовано: 5 ноя 2024

Комментарии • 14

  • @shashwat_tiwari_st
    @shashwat_tiwari_st  5 месяцев назад +2

    like target of this video is 50. If you have other solution, share in comments..

    • @akshgarg5898
      @akshgarg5898 5 месяцев назад

      I code in python but i guess, you'll understand ;)
      class Solution(object):
      def commonChars(self, words):
      """
      :type words: List[str]
      :rtype: List[str]
      """
      q = "abcdefghijklmnopqrstuvwxyz"
      res = []
      for char in q:
      min_count = min(word.count(char) for word in words)
      res.extend([char] * min_count)
      return res

  • @dibakarbera1971
    @dibakarbera1971 5 месяцев назад

    thanks for uploading so many insightful videos. thank you sir

  • @hello-my4yh
    @hello-my4yh 5 месяцев назад

    class Solution {
    public:
    vector commonChars(vector& words) {
    int n=words.size();
    vector ans;
    vector previous(26,INT_MAX);
    vector current(26,0);
    for(int i=0;i

  • @PiyushSharma-we8yd
    @PiyushSharma-we8yd 5 месяцев назад

    first comment.. I was waiting.. thanks for uploading so many insightful videos. Really appreciate your work sir

  • @SH_987
    @SH_987 5 месяцев назад

    Bhaiya, June start ho gya, DP start kr do please🙏🙏🙏🙏🙏 ya phir Graphs ki series.

  • @ishaanrawat967
    @ishaanrawat967 5 месяцев назад

    I tried to take only one array and added all counts and only added the characters into the resultant array that had a frequency in multiples of words.size(). Will this work ?

  • @ancyplayzz
    @ancyplayzz 5 месяцев назад

    class Solution {
    public List commonChars(String[] words) {
    int[] minFreq = count(words[0]);
    for(int i = 1; i < words.length; i++){
    minFreq = intersection(minFreq, count(words[i]));
    }
    List res = new ArrayList();
    for(int i = 0; i < 26; i++) {
    if(minFreq[i] != 0){
    char ch = (char)(i+'a');
    int count = minFreq[i];
    while(count > 0){
    res.add(""+ ch);
    count--;
    }
    }
    }
    return res;
    }
    public int[] intersection(int[] a, int[] b){
    int res[] = new int[26];
    for(int i = 0; i < 26; i++){
    res[i] = Math.min(a[i], b[i]);
    }
    return res;
    }
    public int[] count(String str){
    int[] res = new int[26];
    for(char c : str.toCharArray()){
    int idx = c - 'a';
    res[idx]++;
    }
    return res;
    }
    }

  • @sankalpbarriar1029
    @sankalpbarriar1029 5 месяцев назад

    any plans for videos related to development?

  • @codeDudee
    @codeDudee 5 месяцев назад

    solve without using extra space
    class Solution {
    public List commonChars(String[] words) {
    List ans = new ArrayList();
    String first = words[0];
    for (int i = 0; i < words[0].length(); i++) {
    boolean mainFlag = true;
    char ch = words[0].charAt(i);
    System.out.println("ch is " + ch);
    for (int j = 1; j < words.length; j++) {
    boolean flag = false;
    for (int k = 0; k < words[j].length(); k++) {
    if (ch == words[j].charAt(k)) {
    flag = true;
    String modified = words[j].replaceFirst(Character.toString(words[j].charAt(k)), "*");
    words[j] = modified;
    System.out.println(modified);
    break;
    }
    }
    if (flag == false) {
    mainFlag = false;

    }
    }
    if (mainFlag) {
    ans.add(Character.toString(ch));

    }
    }
    return ans;
    }
    }

  • @mr.nishantawasthi4402
    @mr.nishantawasthi4402 5 месяцев назад

    Sir tree series k baad kya padhne wale hai aur kab se please reply

  • @somith16
    @somith16 5 месяцев назад

    Bhaiya par ye sab toh online assessment toh puch ta hu nahi
    Online assessment kaise face kare uska bhi koi video banao na