Blog Cover Image
Valid Anagram: Check if Two Strings are Anagram or not

Given two strings str1 and str2 of size m and n, write a program to check whether the two strings are an anagram of each other or not. A string str1 is an anagram of str2 if the characters of str1 can be rearranged to form str2.

Blog Cover Image
Hash Functions in Data Structures and Algorithms

We use hash functions to uniformly distributes keys in the hash table. In other words, a good hash function satisfies the assumption of uniform hashing, where each key is equally likely to hash to any slots in the hash table. This blog has discussed the design and properties of some popular hash functions used in programming and data structures.

Blog Cover Image
Hashing and Hash Table in Data Structures and Algorithms

Hashing is a technique to map (key, value) pairs into the hash table using a hash function. It uses an array of size proportional to the number of keys and calculates an array index from the key using a hash function. Explore this blog to learn how hash tables work in programming?

Blog Cover Image
Counting Sort Algorithm

The counting sort algorithm assumes that each n input element is an integer in the range 0 to k. So by using array indexing as a tool for determining relative order, counting sort can sort n numbers in O(k + n) time when k = O(n). In other words, counting sort is one of the popular linear time sorting algorithms that works in O(n) time complexity if input elements are an integer in the range 0 to k.

Blog Cover Image
First Missing Positive

Given an array that includes both positive and negative numbers, write a program to find the first missing positive integer. This is one of the best searching problems for learning step-by-step optimization using various approaches. An in-place hashing solution uses the same input array to process values and generate correct output.

Blog Cover Image
Bloom Filter Data Structure: Introduction and Implementation

Bloom filter is a space-efficient data structure that tells whether an element may be in a set (either a false positive or true positive) or definitely not present in a set (True negative). It will take O(1) space, regardless of the number of items inserted. However, their accuracy decreases as more elements are added.

Blog Cover Image
Least Frequently Used (LFU) Cache Implementation

The least frequently used (LFU) is a cache algorithm used to manage memory within a computer. In this method, the system keeps track of the number of times a block is referenced in memory, and when the cache is full, our system removes the item with the lowest reference frequency.

Blog Cover Image
Implement Least Recently Used (LRU) Cache

The Least Recently Used (LRU) is one of the popular caching strategies, which defines the policy to discard the least recently used items first from the cache and make room for new elements when the cache is full. It is used to organize items in order of their use, which allows identifying items that have not been used for a long time.

Blog Cover Image
Sort Characters by Frequency

Given a string S[], write a program to sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string. If two characters have the same frequency, whichever occurs earliest in S, must come first. In other words, the sorting must be stable.

Blog Cover Image
Length of the Largest Subarray with Zero Sum

Given an array X[] of n integers, find the length of the longest subarray with a sum equal to 0. In general, for all j > i, find max (j - i + 1) among all subarray with zero-sum. Note: the subarray length starting from index i and ending at index j will be j - i + 1. This is an excellent question to learn problem-solving using a hash table.

Blog Cover Image
Fizz Buzz Problem

Given a number n, write a program that outputs the string representation of numbers 1 to n. If the number is divisible by 3, we must say “Fizz”. If the number is divisible by 5, we must say “Buzz”. If the number is divisible by both 3 and 5, we must say “Fizz buzz”. This is an excellent problem to learn coding concepts like if-else, loops, etc.

Blog Cover Image
Count distinct elements in every k size window

Given array X[] of n integers, write a program to return the count of distinct numbers in all windows of size k.

Blog Cover Image
Triplet with Zero Sum

Given an array X[] of distinct elements, write a program to find all the unique triplets in the array whose sum is equal to zero. For example, suppose such triplets in the array are X[i], X[j] and X[k] then X[i] + X[j] + X[k] = 0. Note : solution set must not contain duplicate triplets.

Blog Cover Image
Check if two arrays are equal or not

Given two integer arrays X[] and Y[], write a program to check if the arrays are equal or not. Two arrays are equal if they have the same elements in any order. If there are repeated elements, then counts of repeated elements must also be the same for both arrays.

Blog Cover Image
Longest Substring Without Repeating Characters

Write a program to find the length of the longest substring without repeating characters. Substring is the continuous sub-part of the string. The aim is to determine the maximum such subpart which has all the unique characters.

Blog Cover Image
Longest Consecutive Sequence

Given an array X[] of n integers, write a program to find the length of the longest consecutive elements sequence. In other words, we need to find the length of the longest sub-sequence such that elements in the subsequence are consecutive integers. The consecutive numbers can be in any order.

Blog Cover Image
Find most frequent element in an array

Given an array X[] of size n, write a program to find the most frequent element in the array, i.e. the element which occurs the most number of times. It is assumed that at least one element is repeated.

Blog Cover Image
Find whether an array is a subset of another array

We are given two integer arrays X[] and Y[], write a program to check whether array Y[] is a subset of array X[] or not. An array Y is a subset of another array X if each Y element is present in X. How do you check if one array is a subset of another? Explore and Enjoy!

Blog Cover Image
Find Majority Element in an Array

You are given an array X[] consisting of n elements, write a program to find majority element in an array i..e return the number which appears more than n/2 times. You may assume that the array is non-empty and the majority element always exists in the array. A majority element is an element that appears more than n/2 times, so there is at most one such element.

Blog Cover Image
Check for pair in an array with a given sum

Given an array of n integers and a target number, write a program to check whether a pair sum exits in the array or not. In other words, we need to check whether pair of elements in the array sum exactly to the target value.

Blog Cover Image
n Repeated element in 2n size array

In an array of size 2n, there are n+1 unique elements, and exactly one of these elements is repeated n times. Return the element repeated n times.

Our weekly newsletter

Subscribe to get free weekly content on data structure and algorithms, machine learning, system design, oops design and mathematics.

Follow us on:


© 2020 EnjoyAlgorithms Inc.

All rights reserved.