VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » freeCodeCamp.org
10 Common Coding Interview Problems - Solved!

10 Common Coding Interview Problems - Solved!

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
Preparing for coding interviews? Competitive programming? Learn to solve 10 common coding problems and improve your problem-solving skills. - Code: https://gist.github.com/syphh/173172ec9a4a1376e5096a187ecbddc9 https://gist.github.com/syphh/173172ec9a4a1376e5096a187ecbddc9 -- Course developed by Inside code. Check out their YouTube channel: https://www.youtube.com/channel/UCvLEP7Hu6SHd5a2CWeQXalg
Date: 2022-03-14

Comments and reviews: 10


Problem Solution - 1 in Swift:
func areAnagrams(s1: String, s2: String) -> Bool -
if s1.count != s2.count - return false -
var s1Frequency: [String: Int] = [:]
var s2Frequency: [String: Int] = [:]
for char in s1 -
s1Frequency[-\(char)-, default: 0] += 1
-
for char in s2 -
s2Frequency[-\(char)-, default: 0] += 1
-
for key in s1Frequency.keys -
if s2Frequency.keys.contains(key) == false -- s1Frequency[key] != s2Frequency[key] -
return false
-
-
return true
-

reply

There is a faster method of solving for the Kth largest element. 1. We walk through the array and put elements into the max-heap only for i = 1 to k. 2. For i = k to N, where N = len(arr), we only add arr[i] to the max-heap if arr[i] > heap.peek(). We also have to pop one element to maintain the heap length to k. 3. Once we have completely walked through the array, we return the top element from the heap. Thus we construct a heap of only k elements and walk through the array once.
reply

I have been a developer for more than 20 years. In the last 10 (or less) of that, I have seen a lot of -interview questions- that are basically just -show you know algorithms-. What I have not seen much at all are real world examples of how these are used. For example, show me a website on the internet where the developer needed to understand how to solve the anagram problem?
reply

Hi, I am a beginner in Python but I think the second problem has a very simple solution only in 5 lines.:
def find_first_last(arr, tar):-
l2 = []-
for index, num in enumerate(l):-
if num == tar:-
l2.append(index)-
return [l2[0], l2[-1]]-
l = [2, 4, 5, 5, 5, 5, 5, 7, 9, 9]-
print(find_first_last(l, 5))

reply

Just a note on the 'valid anagram' problem -- if you're going to use python sorted() function to compare strings you'll need to lowercase them first. Otherwise 'danger' and 'gArden' won't be considered anagrams. Sorting for that problem was not the most efficient solution, but it's good to be aware of the gotchas!
reply

This would of been great. I have to ask though, did you gargle lidocaine? Was it cold where you recorded this and you couldnt feel your face? Maybe you were a little drunk? Makes the video unwatchable as far as im concerned. I can't listen to monotone mumble mouth talk about algos for 2 hours and still be conscious.
reply

Just iterating through only ONCE in a string and checking if the character is in the other string, probably less time complexity, and definietly less space complexity (you are not using any extra spaces in that case).
it depends on the implementation of the string contains actually... It is probably O(n)

reply

3:19 For the anagram you can use 1 hash table but on the 2nd loop when you ask if the character of the second word is not on the table , return false.
If it is on the table then rest 1 on that key.
At the end ask if any value on the hash is not zero , return False.
At last you can return True.

reply

Can you please use Java next time? The code is more comprehensive and much more readable when looking at a HARD problem such as the minimum window substring. I believe Python is very concise but when trying to understand a new concept, can be a little less readable as compared to Java or even C++.
reply

28:36 no need for a stack
just have a variable that represents at what nest level you're at (if c == '(' nestLevel++; if c == ')' nestLevel--)
if it ever becomes negative return false and at the end of the loop it should be equal to 0

reply
Add a review, comment






Other channel videos