avatarAkshay Ravindran

Summary

The website article lists nine challenging Leetcode problems suitable for practice by individuals aiming to secure software engineering roles at FAANG companies.

Abstract

The article titled "9 Hard Leetcode Problems to Challenge yourself in 2022" provides a curated list of difficult coding problems from Leetcode that are often encountered in technical interviews for FAANG companies. These problems are categorized as 'Hard' and are designed to test a candidate's problem-solving skills using algorithms and data structures. The author emphasizes that mastering these problems is crucial for interview preparation, suggesting that grinding through all 1300 problems on Leetcode is unnecessary. Instead, focusing on these selected problems can be the first step towards securing a job. The list includes tasks such as finding the count of smaller numbers after self, determining the median of two sorted arrays, and solving the word ladder problem, among others. The article also includes links to the problems on Leetcode, enabling readers to practice directly.

Opinions

  • The author believes that solving these specific hard Leetcode problems is a more efficient way to prepare for coding interviews compared to attempting all problems on the platform.
  • There is an opinion that the problems listed are representative of the challenges one might face in a FAANG interview.
  • The article suggests that there is a direct correlation between practicing these problems and improving one's chances of getting a job at a top tech company.
  • The author implies that understanding the median and how to find it in various scenarios is particularly important, as evidenced by the inclusion of two problems related to medians.
  • By providing a sequential list of problems, the author seems to advocate for a structured approach to problem-solving and interview preparation.
  • The inclusion of a problem involving converting integers to English words indicates the author's view that versatility in problem-solving, beyond traditional algorithmic challenges, is also valuable.

9 Hard Leetcode Problems to Challenge yourself in 2022

Photo by Jukan Tateisi on Unsplash

Introduction

If you are trying to get into FAANG companies, then there are probably 3–5 technical rounds where you would be asked to solve different problems using Algorithms and Data Structures.

The last few posts in the series were focused on Easy and Medium difficulty Leetcode problems that are prevalently asked in Software Engineer Interviews. The following set of problems are also asked in FAANG interviews, these are tagged as Hard.

I am not asking you to go and grind through all 1300 problems over there to become the best problem solver these companies look for. Instead, I have garnered a list of questions that get you started with this.

I consider this list to be the first step in getting the job you deserve. Leetcode: https://leetcode.com/explore/

Now, let’s go to the list

1) Count of Smaller Numbers After Self

You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].

Input: nums = [5,2,6,1]
Output: [2,1,1,0]
Explanation:
To the right of 5 there are 2 smaller elements (2 and 1).
To the right of 2 there is only 1 smaller element (1).
To the right of 6 there is 1 smaller element (1).
To the right of 1 there is 0 smaller element.

Try this problem

2) Median of Two Sorted Arrays

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

Input: nums1 = [1,3], nums2 = [2]
Output: 2.00000
Explanation: merged array = [1,2,3] and median is 2.

Try this problem

3) First Missing Positive

Given an unsorted integer array nums, return the smallest missing positive integer.

Input: nums = [1,2,0]
Output: 3
Input: nums = [3,4,-1,1]
Output: 2

Try this problem

4) Trapping Rain Water

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]
Output: 6
Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.

Try this problem

5) Word Ladder

A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:

  • Every adjacent pair of words differs by a single letter.
  • Every si for 1 <= i <= k is in wordList. Note that beginWord does not need to be in wordList.
  • sk == endWord

Given two words, beginWord and endWord, and a dictionary wordList, return the number of words in the shortest transformation sequence from beginWord to endWord, or 0 if no such sequence exists.

Input: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]
Output: 5
Explanation: One shortest transformation sequence is "hit" -> "hot" -> "dot" -> "dog" -> cog", which is 5 words long.

Try this problem

6) Find Minimum in Rotated Sorted Array II

Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become:

  • [4,5,6,7,0,1,4] if it was rotated 4 times.
  • [0,1,4,4,5,6,7] if it was rotated 7 times.

Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].

Given the sorted rotated array nums that may contain duplicates, return the minimum element of this array.

You must decrease the overall operation steps as much as possible.

Input: nums = [1,3,5]
Output: 1
Input: nums = [2,2,2,0,1]
Output: 0

Try this problem

7) Closest Binary Search Tree Value II

Given the root of a binary search tree, a target value, and an integer k, return the k values in the BST that are closest to the target. You may return the answer in any order.

You are guaranteed to have only one unique set of k values in the BST that are closest to the target.

Input: root = [4,2,5,1,3], target = 3.714286, k = 2
Output: [4,3]
Input: root = [1], target = 0.000000, k = 1
Output: [1]

Try this problem

8) Integer to English Words

Convert a non-negative integer num to its English words representation.

Input: num = 123
Output: "One Hundred Twenty Three"
Input: num = 12345
Output: "Twelve Thousand Three Hundred Forty Five"

Try this problem

9) Find Median from Data Stream

The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values.

  • For example, for arr = [2,3,4], the median is 3.
  • For example, for arr = [2,3], the median is (2 + 3) / 2 = 2.5.

Implement the MedianFinder class:

  • MedianFinder() initializes the MedianFinder object.
  • void addNum(int num) adds the integer num from the data stream to the data structure.
  • double findMedian() returns the median of all elements so far. Answers within 10-5 of the actual answer will be accepted.

Try this problem

End of the Line

Thank you for reading the article. Good luck with your Programming Interview! Next post coming soon

Support us in bringing more articles to you by becoming a member.

Coding
Software Development
Programming
Java
Algorithms
Recommended from ReadMedium