Technical Interview thoughts and 242 Valid Anagram

Mariah Morales
3 min readJul 15, 2022

After doing the Spotify Fellowship interview, I must say that I understand why people go so hard on practicing with Data Structures and Algorithms. I actually surprisingly did decently well especially for it being my first actually technical interview.

Interviews I had done prior were either behavioral, pseudocode or just some technical questions. Let me say that I definitely was sweating up a major storm, struggled a bit in the first half but found my footing toward the very end and even managed to complete it.

My history with Data Structures and Algorithms started off with a rough start. I honestly would not have been able to even know where to begin if you were interviewing me a few months ago.

At least now if I see some primitive values, I have a general understanding of how I could achieve an answer or at least manipulate to get close to solving. CodeWars gave me a solid foundational understanding of data structures and algorithms and I am hoping soon to move on to leetcode fully for the much complex. I had gotten some great advice from my interviewer too. They said that the way they practiced was basically writing by hand the answer or solutions and then basically trying to solve it without their answer.

As time goes on, you will begin to notice patterns to be able to solve the problems! During my interview, I feel that I kind of utilized a pattern I have been seeing. I really think it helped me at least talk through a possibly solution.

Well without further ado let’s do a leetcode problem!

242 Valid Anagram

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.

Example 1:

Input: s = "anagram", t = "nagaram"
Output: true

Example 2:

Input: s = "rat", t = "car"
Output: false

Constraints:

  • 1 <= s.length, t.length <= 5 * 104
  • s and t consist of lowercase English letters.

Looking at this problem I kinda didn’t know where to begin initially but one of the easiest ways to compare things that have the same letters is a quick little sort for both strings…

Just one thing….

The .sort() method are used for arrays…we have strings..

Let’s simply turn our strings into an array!

We can do this with the .split() method.

Cool! Obviously, there is still much to add as these arrays obviously are not equal to one another. We can now use the sort method to sort the respective letters alphabetically.

Cool, we have an alphabetized array… we need to turn it back into a string now! Simple use the .join method to do so!

Here is the finished product!

If we run this code and the strings match, we should get an output of true. Obviously, if they do not match, this will be false.

I hope this was helpful to you all!

--

--