**What is Registry Pattern?**

Registry should be understood as a global object that maintains track of instances. This global is usually a dictionary or an associate array with the keys being the identifiers for the values stored in the dictionary.

Registry should be understood as a global object that maintains track of instances. This global is usually a dictionary or an associate array with the keys being the identifiers for the values stored in the dictionary.

Given a string, find the length of the longest substring without repeating characters.

Example 1:

```
Input: "abcabcbb"
Output: 3
Explanation: The answer is
````"abc"`

, with the length of 3.

Example 2:

```
Input: "bbbbb"
Output: 1
Explanation: The answer is
````"b"`

, with the length of 1.

Example 3:

Input: "pwwkew" Output: 3 Explanation: The answer is`"wke"`

, with the length of 3. Note that the answer must be a substring,`"pwke"`

is asubsequenceand not a substring

[Original Link]

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have *exactly* one solution, and you may not use the *same* element twice.

Example:

Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].

Solution:

The idea is to maintain a hash map to store the elements that you have seen as we iterate over the array. For every number we try to see if we have a complement i.e (target-current no) in our hash map. If we find the number in our hash map, we have our answer.

Space Complexity: O(n)

Time Complexity: O(n)

These questions are in no particular order. Every question will give you enough exposure to strategies and techniques required to solve most of the problem solving & data structures related questions in the interviews.

Some of the techniques used in these problems are two pointers, invariant windows, binary search, DFS/BFS, recursion, interval scheduling related, simple DP and bit manipulation, heaps, data structure design etc.

Some of the techniques used in these problems are two pointers, invariant windows, binary search, DFS/BFS, recursion, interval scheduling related, simple DP and bit manipulation, heaps, data structure design etc.

- Two Sum
- 3Sum
- Combination Sum
- Minimum Window Substring
- Maximum Subarray
- Longest substring without repeating characters
- Longest Palindromic Substring
- Longest repeating character replacement
- Search in a rotated sorted array
- Maximum Subarray
- Spiral Matrix
- Rotate Image
- Container with most Water
- Best Time to Buy and Sell Stock
- Remove Nth Node from end of a list
- Maximum Product Subarray
- Reverse LinkedList
- Product of Array Except Self
- Find minimum in rotated sorted array
- Valid Parenthesis
- Merge two sorted lists
- Merge K sorted lists
- Group Anagrams
- Merge Intervals
- Meeting Rooms
- Meeting Rooms ||
- Minimum Number of arrows to burst balloons
- Insert Interval
- Unique Paths
- Jump Game
- Climbing Stairs
- Set Matrix Zeros
- Word Search
- Word Search ||
- Validate Binary Search Tree
- Binary Tree Level Order Traversal
- Maximum Depth of a Binary Tree
- Binary Tree from Preorder and Inorder traversals
- Binary Tree Maximum Path Sum
- Invert Binary Tree
- Kth Smallest Element in a BST
- Lowest Common Ancestor in a BST
- Serialize and deserialize binary tree
- Subtree of Another Tree
- Number of connected components in an undirected graph
- Clone Graph
- Valid Palindrome
- Longest Consecutive Sequence
- Word Break
- Decode Ways
- Linked List Cycle
- Reorder List
- Reverse Bits
- Number of 1 Bits
- House Robber
- House Robber ||
- Number of Islands
- Implement Trie
- Add and Search Word - DS Design
- Contains Duplicate
- Course Schedule
- Valid Anagram
- Group Valid Tree
- Missing Number
- Alien Dictionary
- Encode And Deode Strings
- Find Median from data stream
- Longest Increasing Subsequence
- Coin Change
- Counting Bits
- Top K frequent elements
- Sum of Two Integers
- Pacific Atlantic Water flow
- Non Overlapping Intervals

You've been working on a particularly difficult algorithm all day, and finally decided to take a break and drink some coffee. To your horror, when you returned you found out that your cat decided to take a walk on the keyboard in your absence, and pressed a key or two. Your computer doesn't react to letters being pressed when an unauthorized action appears, but allows typing whitespace characters and moving the arrow keys, so now your masterpiece contains way too many whitespace characters.

To repair the damage, you need to start with implementing a function that will replace all multiple space characters in the given

`line`

of your code with single ones. In addition, all leading and trailing whitespaces should be removed.
For

the output should be

`line = "def m e gaDifficu ltFun ction(x):"`

,the output should be

`catWalk(line) = "def m e gaDifficu ltFun ction(x):"`

.**[execution time limit] 4 seconds (py)****[input] string line**One line from your code containing way too many whitespace characters.*Guaranteed constraints:*`5 ≤ line.length ≤ 125`

.**[output] string**`line`

with unnecessary whitespace characters removed.

def catWalk(code): return " ".join(code.strip().split())

To understand how efficient the built-in Python sorting function is, you decided to implement your own simple sorting algorithm and compare its speed to the speed of the Python sorting. Write a function that, given an array of integers

`arr`

, sorts its elements in ascending order.`...`

).
For

`arr = [2, 4, 1, 5]`

, the output should be`simpleSort(arr) = [1, 2, 4, 5]`

.**[execution time limit] 4 seconds (py)****[input] array.integer arr***Guaranteed constraints:*

`1 ≤ arr.length ≤ 100`

,

`-10`

.^{5}≤ arr[i] ≤ 10^{5}**[output] array.integer**The given array with elements sorted in ascending order.

We just have to swap the elements which are out of order. The line in bold does just that. Its called tuple unpacking.

def simpleSort(arr): n = len(arr) for i in range(n): j = 0 stop = n - i while j < stop - 1: if arr[j] > arr[j + 1]:arr[j], arr[j+1] = arr[j+1], arr[j]j += 1 return arr

Implement the missing code, denoted by ellipses. You may not modify the pre-existing code.

Implement a function that, given an integer

`n`

, uses a specific method on it and returns the number of bits in its binary representation.`...`

). Only this part is allowed to be changed.
For

`n = 50`

, the output should be`countBits(n) = 6`

.`50`_{10} = 110010_{2}

, a number that consists of `6`

digits. Thus, the output should be `6`

.**[execution time limit] 4 seconds (py)****[input] integer n**A positive integer.*Guaranteed constraints:*`1 ≤ n ≤ 10`

.^{9}**[output] integer**The number of bits in binary representation of`n`

.

It is expected to only replace the ellipsis with the code that would give you the bit length of the given integer.

def countBits(n):

return n.bit_length()

Subscribe to:
Posts (Atom)