DEV Community

DFS With Memo
DFS With Memo

Posted on

Must know beginner algorithms

Introduction

In this post I will list warm up problems that will help you get a sense of the algorithm. I highly recommend you to solve the problems in my previous post before solving the problems here.

I have noted things you should keep in mind when thinking about the algorithm. This is not an exhaustive list. To have a good interview you need regular and consistent practice with a dash of luck.

I hope the list of problems here would help you ease into solving Leetcode style problems and allow you to form a habit of problem solving which you can then use to solve more difficult problems.

Table of contents

Index

Topics

Two pointers

Two pointers usually work by having two variables, one that is at the start of the array and another at the end. There would be some logic that would move the start pointer to the left and the end pointer to the right. The algorithm terminates when the two pointers cross over.

Reverse String

Is subsequence

Valid palindrome

Squares of sorted array

Binary Search

Binary search is a special type of two pointer algorithm. It's an algorithm that searches over a solution space drastically reducing(by half) the space in every iteration.

One of the main goals of solving these type of problems is to become familiar is how to use binary search. It may not always be apparent because you have to apply binary search with another data set which may not be your input data.

Binary Search

Valid perfect squre

Sqrt(x)

First Bad Version

Sum of mutated array closest to target

Sliding Window

The sliding window technique is used for solving problems that deal with contiguous subarrays such as finding the minimum subarray size that adds up to a given target sum.

Sliding window is useful in situations where you don't want to recompute everything inside the window. Here I provide few easy problems and (easy) medium level problems that can be solved with sliding window.

A common question that comes to mind is what is the difference between sliding window and two pointers? Both algorithms require two variables to track indices. How I like to see it is that, in sliding window we are concerned with the elements within the window whereas in two pointers we are concerned with the elements that the two variables are pointing at.

It's a pet peeve of mine when people mention two pointers and do a sliding window.

Maximum Average Subarray 1

Contains Duplicate 2

Longest Substring Without Repeating Characters

Minimum sub-array sum

Minimum size subarray sum

Sorting

Many problems become easier to solve when you sort the data. Sometimes you might have to use sorting in an innovative way. For these types of problems, you should be familiar with how to use the in-built sort function in your programming language.

It's not mandatory to know how to implement your own sorting algorithm but you should be familiar with the merge helper function used by merge sort and the partition helper function used by quick sort as these helper functions can be used in different problems. If you know these two helper functions, you should be able to implement quick sort and merge sort.

Another sorting algorithm is Counting sort which let's you sort data in O(n) time.

It is critical to know the time complexities of different sorting algorithms as well as the sorting algorithm used by the in-built sorting function.

Sort Colors

Valid Anagram

Relative ranks

Sort Array by Parity

Relative sort Array

Maximum Units on a Truck

Top comments (0)