Doing a coding challenge - live stream - First Unique Character in a String!
Join me to work through a coding challenge live from Leetcode.com called First Unique Character in a String!
Problem:
Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.
Solution summary:
— Intuition / tip: Use an object/map to store the frequency of each character first
— Create an object/map to hold frequencies
— Loop the input array - for each item either add it to the map with a value of 1, or increment the value if already in the map
— Loop the values of the string
— For each item check if the frequency in the map equals to 1, if so, return that index (that is the index of the first unique character). If not, keep looping.
— Return -1 at the end the function (there is no unique character if we get here)
— Time complexity: O(n) where ’n’ is the number of characters of the input string
— Space complexity: O(n) where ’n’ is the number of characters of the input string
Let me know if you have any questions or see ways I could have optimized!
Bonus: at the end of the video I answer questions.
Let's connect!
🌐 Website | https://www.kg.codes
📺 Subscribe | www.youtube.com/channel/UCfv7SNcMWwn8QANjD7AgY5w?sub_confirmation=1
📷 Instagram | www.instagram.com/kg.codes/
🎵 TikTok | https://www.tiktok.com/t/ZTRLxP4wf/
🐦 Twitter | www.twitter.com/kgcodes/
Get my coding gear / desk setup 👨🏾💻
📦 Amazon | https://www.amazon.com/shop/kg.codes/list/3E7C7N52AFY8R
Видео Doing a coding challenge - live stream - First Unique Character in a String! канала KG.codes
Problem:
Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.
Solution summary:
— Intuition / tip: Use an object/map to store the frequency of each character first
— Create an object/map to hold frequencies
— Loop the input array - for each item either add it to the map with a value of 1, or increment the value if already in the map
— Loop the values of the string
— For each item check if the frequency in the map equals to 1, if so, return that index (that is the index of the first unique character). If not, keep looping.
— Return -1 at the end the function (there is no unique character if we get here)
— Time complexity: O(n) where ’n’ is the number of characters of the input string
— Space complexity: O(n) where ’n’ is the number of characters of the input string
Let me know if you have any questions or see ways I could have optimized!
Bonus: at the end of the video I answer questions.
Let's connect!
🌐 Website | https://www.kg.codes
📺 Subscribe | www.youtube.com/channel/UCfv7SNcMWwn8QANjD7AgY5w?sub_confirmation=1
📷 Instagram | www.instagram.com/kg.codes/
🎵 TikTok | https://www.tiktok.com/t/ZTRLxP4wf/
🐦 Twitter | www.twitter.com/kgcodes/
Get my coding gear / desk setup 👨🏾💻
📦 Amazon | https://www.amazon.com/shop/kg.codes/list/3E7C7N52AFY8R
Видео Doing a coding challenge - live stream - First Unique Character in a String! канала KG.codes
coding challenge leetcode problem leetcode challenge leetcode easy programming problem coding leetcode coding challenges coding interview coding interview practice leetcode practice leetcode practice problem hackerrank first unique character first unique character in a string first unique character in a string solution first unique character in a string leetcode leetcode first unique character in a string
Комментарии отсутствуют
Информация о видео
16 января 2023 г. 22:37:32
01:21:37
Другие видео канала