0% found this document useful (0 votes)
200 views

My Solutions to Blind 75 - LeetCode Discuss

The document presents solutions to problems from the Blind 75 list on LeetCode, including matrix rotation and grouping anagrams. It includes code snippets in Python and Go, detailing the algorithms and their time and space complexities. The solutions focus on efficient data manipulation techniques for common coding interview questions.

Uploaded by

Vedaant Dutt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
200 views

My Solutions to Blind 75 - LeetCode Discuss

The document presents solutions to problems from the Blind 75 list on LeetCode, including matrix rotation and grouping anagrams. It includes code snippets in Python and Go, detailing the algorithms and their time and space complexities. The solutions focus on efficient data manipulation techniques for common coding interview questions.

Uploaded by

Vedaant Dutt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

25/12/2024, 17:39 My Solutions to Blind 75 - LeetCode Discuss

Explore Problems Contest Discuss Interview Store 0

#Transpose
n = len(matrix)
for i in range(n):
for j in range(i):
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]

#Swap columns
for i in range(n):
matrix[i] = matrix[i][::-1]

//Go
func reverse(array []int) []int {
m := len(array)
for i := 0; i < m/2; i++ {
array[i], array[m-i-1] = array[m-i-1], array[i]
}
return array
}

func rotate(matrix [][]int) {


n := len(matrix)
for i := 0; i < n; i++ {
for j := 0; j < i; j++ {
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
}
}

for i := 0; i < n; i++ {


matrix[i] = reverse(matrix[i])
}

Group Anagrams
Time Complexity: O(n ⋅ k log k) -|- k = length of longest anagram
Space Complexity: O(n)

#Python3
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
mapper = {}

for string in strs:


sorted_str = str(sorted(string))
if sorted_str in mapper:
mapper[sorted_str].append(string)
else:
mapper[sorted_str] = [string]

return list(mapper.values())

golang python3 go blind 75 grind 75

Comments: 0 Best Most Votes Newest to Oldest Oldest to New

https://leetcode.com/discuss/interview-question/4915703/my-solutions-to-blind-75 1/1

You might also like