Перейти к содержимому

LeetCode #760: Find Anagram Mappings, Value to Index Hash Map

Brute To Best

0:00 / 0:00

LeetCode #760: Find Anagram Mappings, Value to Index Hash Map

1 просмотр · 7 ч назад
Brute To Best
101 подписчик
1 просмотр · 7 ч назад
Brute to Best: every LeetCode problem, from the naive solution to the optimal one. In this video: The problem: nums2 is an anagram of nums1. For each element of nums1, return an index where that value appears in nums2. Brute force: search nums2 for each value, which is O(N²). The key insight: build a hash map from each value in nums2 to its index once, then each lookup takes O(1). If there are duplicate values, any matching index is accepted. Dry run: with nums1 = 12, 28, 46, 32, 50 and nums2 = 50, 12, 32, 46, 28, the answer is 1, 4, 3, 2, 0. Complexity: O(N) time and O(N) space. Problem: https://leetcode.com/problems/find-an... Related: Two Sum (1), Valid Anagram (242), Intersection of Two Arrays II (350) Full Brute to Best playlist on the channel. Subscribe for a new LeetCode problem, solved from brute force to the best solution, every day. Hashtags #leetcode #leetcode760 #findanagrammappings #hashtable #hashmap #array #easy #coding #codinginterview #dsa #python #leetcodepremium #google #faang #brutetobest