Input: points = [[1,3],[-2,2]], K = 1
Output: [[-2,2]]
Explanation:
The distance between (1, 3) and the origin is sqrt(10).
The distance between (-2, 2) and the origin is sqrt(8).
Since sqrt(8) < sqrt(10), (-2, 2) is closer…

1. Knuth-Morris-Pratt Algorithm and

2. Divisors + Rabin-Karp

Input: "abab"
Output: True
Explanation: It's the substring "ab" twice.
Input: "aba"
Output: False
Input: "abcabcabcabc"
Output: True
Explanation: It's the substring "abc" four times. (And the substring "abcabc" twice.)

  • If the character read is a letter, that letter is written onto the tape.
  • If the character read is a digit (say d), the entire current tape is repeatedly written d-1 more times in total.
Input: S = "leet2code3", K…

struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
  • You may only use constant extra space.
  • Recursive approach is fine, you may assume implicit stack space does not count as extra space…

Input: [1,2,3,null,5,null,4]
Output: [1, 3, 4]
Explanation:
1 <---
/ \
2 3 <---
\ \
5 4 <---

1
/ \
2 2
/ \ / \
3 4 4 3
1
/ \…

    3
/ \
9 20
/ \
15 7
There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class…

  1. Its good to point out the differences in the space complexity of the BFS (using a queue) and DFS (recursion ) approaches.
  2. Both solutions are below.
    3
/ \
9 20
/ \
15 7
[
[3],
[20,9],
[15,7]
]
  1. It is quite evident that we are traversing one level at…

Problem


Problem

For example:

Technical Interviews Preparation

Currently preparing for interviews

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store