Must know beginner algorithms
Tags: beginners, programming, interview, codenewbie
Published: 2023-06-25 21:43:32

## 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](https://dev.to/dfs_with_memo/leetcode-warmup-problems-13o7) 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
  * [Two pointers](#twoptr)
  * [Binary Search](#binsearch)
  * [Sliding Window](#sw)
  * [Sorting] (#sort)


### Topics

### Two pointers <a name="twoptr"></a> 

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](https://leetcode.com/problems/reverse-string/)

[Is subsequence](https://leetcode.com/problems/is-subsequence/)

[Valid palindrome](https://leetcode.com/problems/valid-palindrome/)

[Squares of sorted array](https://leetcode.com/problems/squares-of-a-sorted-array/)

### Binary Search <a name="binsearch"></a> 

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](https://leetcode.com/problems/binary-search/)

[Valid perfect squre](https://leetcode.com/problems/valid-perfect-square/)

[Sqrt(x)](https://leetcode.com/problems/sqrtx/)

[First Bad Version](https://leetcode.com/problems/first-bad-version/)

[Sum of mutated array closest to target](https://leetcode.com/problems/sum-of-mutated-array-closest-to-target/)


### Sliding Window <a name="sw"></a> 

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](https://leetcode.com/problems/maximum-average-subarray-i/)

[Contains Duplicate 2](https://leetcode.com/problems/contains-duplicate-ii/)

[Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/)

[Minimum sub-array sum](https://leetcode.com/problems/minimum-size-subarray-sum/)

[Minimum size subarray sum](https://leetcode.com/problems/minimum-size-subarray-sum/)

### Sorting <a name="sort"></a> 

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](https://www.geeksforgeeks.org/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](https://leetcode.com/problems/sort-colors/)

[Valid Anagram](https://leetcode.com/problems/valid-anagram/)

[Relative ranks](https://leetcode.com/problems/relative-ranks/)

[Sort Array by Parity](https://leetcode.com/problems/sort-array-by-parity/)

[Relative sort Array](https://leetcode.com/problems/relative-sort-array/)

[Maximum Units on a Truck](https://leetcode.com/problems/maximum-units-on-a-truck/)