filmov
tv
Coding Challenge from Leetcode - Valid Anagram

Показать описание
Problem: Given two strings s and t, return true if t is an anagram of s, and false otherwise. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Solution summary: either sort both strings and check if they are equal, or use a letter frequency map to compare them
1. Option 1: Sorting strings:
1. Sort both strings - O(n log n) time
2. Check if they are equal to know if an anagram
2. Option 2: Use frequency map
1. Loop through first string, putting each letter into the map, and incrementing the value (frequency) per letter
2. Loop through the second string, checking if the letter is in the map; if so decrement the value (frequency); if not, return false (not an anagram)
3. Loop through the map and if any value is not zero, return false (not an anagram)
4. If gotten to this point without returning false, then return true (is an anagram)
Let me know if you have any questions or see ways I could have optimized!
Let's connect!
Get my coding gear / desk setup 👨🏾💻
How To Pass Technical Interviews When You Suck At LeetCode
Leetcode 1-hour coding challenge | FAANG
4 Steps to Solve Any Dynamic Programming (DP) Problem
Top 6 Coding Interview Concepts (Data Structures & Algorithms)
LeetCode Coding Challenge - Add Two Numbers (2019)
Master the 'Two Sum' Coding Challenge with PHP in Minutes! | LeetCode
INTERVIEW CODING CHALLENGES
15 min Swift coding challenge - Valid Parentheses
Longest Common Prefix Leetcode Problem #014| Python #coding #leetcode #programming #python #code
Google Medium Dynamic Programming Problem - Leetcode 64 - Minimum Path Sum
100 Day Coding Challenge #study #coding #challenge #softwareengineer #dsa
Climbing Stairs - Dynamic Programming - Leetcode 70 - Python
Google Dynamic Programming Problem - Coin Change - Leetcode 322
Solving Coding Interview Questions in Python on LeetCode (easy & medium problems)
How to NOT Fail a Technical Interview
Python Best Solution to the Two Sum Problem (Leetcode 1) #coding #codinginterview #python
Always solve a weird leetcode Problem! 🤬😭 | Programming Tips
Whiteboard Coding Interviews: 6 Steps to Solve Any Problem
Solve This Coding Problem and Win $200
Daily Coding Challenge 16 #leetcode #shorts
How to Actually Prepare for Coding Challenges #code #softwaredevelopment #leetcode
When you practice 300 coding challenges but in the interview forget everything on a Leetcode easy 🥲...
10 Common Coding Interview Problems - Solved!
Two Sum - Leetcode 1 - HashMap - Python
Комментарии