First Unique Character in a String | LeetCode problem 387

preview_player
Показать описание
First Unique Character in a String
Leetcode problem number 387
Solution in JAVA

JAVA interview programming playlist:

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

very easy explaination....So beautiful, So elegent, Just looking like wow...

mayappapujari
Автор

Nice explanation!💫

I thought this approach store characters in hashmap table, after that iterate over string while checking the frequency of each character, we don't have to initialize the 26 alphabets space unless given string contains all the alphabet.

nikhilkumarjamwal
Автор

HashMap<Character, Integer> charCount = new HashMap<>();

// Step 1: Count the frequency of each character
for (char ch : s.toCharArray()) {
charCount.put(ch, charCount.getOrDefault(ch, 0) + 1);
}

// Step 2: Find the first character with frequency 1
for (int i = 0; i < s.length(); i++) {
if (charCount.get(s.charAt(i)) == 1) {
return i; // Return the index of the first unique character
}
}
return -1; // If no unique character found
}

DevOpsMIS
Автор

Software Engineer at Oracle 🤯
Aee baba mast package hoga.... Lol

akashyadav
Автор

if I pass 'z' as an input test case, I am getting failed @technosage, i think we should change the loop condition to for (int i=0;i<ch.length;i++)? please correct me if wrong

hariprasad-hzpk
Автор

this question could be solved by using an ordered map as well right?

omkarshendge
Автор

Very well ❤️‍🩹❤️‍🩹❤️‍🩹❤️‍🩹❤️‍🩹❤️‍🩹❤️‍🩹 explanation

nazim
join shbcf.ru