GithubHelp home page GithubHelp logo

manoj2411 / ds-algo Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 6.0 3.4 MB

Must do Data Structures and Algorithms problems and solutions

License: GNU General Public License v3.0

Ruby 84.75% Python 0.79% Scala 0.02% JavaScript 0.02% Java 14.42%
algorithm algorithms algorithm-challenges algorithms-datastructures algorithms-and-data-structures data-structures datastructures datastructure algorithims-in-ruby ds-algo-in-ruby

ds-algo's Introduction

ds-algo

Playground for popular algorithms and data-structures problems.

Problems

Graphs

  • Snake and Ladder Problem: Given a snake and ladder game, find the minimum number of dice throws required to reach the destination from source. (Solution)

  • Course Schedule There are a total of numCourses courses you have to take, labeled from 0 to numCourses-1. There are course prerequisites like [0,1], meaning to take 0 you have to 1 first. Find out if it is possible for you to finish all courses? Ref. (Solutions: ruby, java)

  • Reorder Routes to Make All Paths Lead to the City Zero, ref. (Solution)

  • Cheapest Flights Within K Stops ref. (Solution)

  • Surrounded Regions Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded region, ref. (Solution)

  • Find shortest distances between every pair of vertices of weighted directed Graph - Floyd–Warshall's Algorithm, ref. (solution)

Arrays

  • Binary search (Solution)

  • Ternary Search (Solution)

  • Subarray with given sum, non-negative numbers. (Solution)

  • Rearrange an array in maximum minimum form, O(1) extra space. (Solution)

  • Maximum Subarray: given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. (Solution)

  • Move all zeroes to end of array with minimum operations and in-place (Solution)

  • Sort an array of 0s, 1s and 2s (Solution)

  • Equilibrium point/index of an array (Solution)

  • Reverse an array in groups of given size (details). solution

  • Counting Elements - Given an integer array, count element x such that x + 1 is also in array. If there're duplicates in array, count them seperately. (Solution)

  • Last Stone Weight - Given an integer array as collection of stones, Each turn, we choose the two heaviest stones and smash them together. The result of this smash is: If x == y, both stones are totally destroyed otherwise weight of x is destroyed, and the stone of weight y has new weight y-x (Solution) (Solution in java)

  • Contiguous Array Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. (Solution)

  • Product of Array Except Self Given an array of integers, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Without using division. (Solution)

  • Find the point where maximum intervals overlap (Solution)

  • Maximum Sum Circular Subarray (Solution)

  • Online Stock Span : collect daily price quotes of a stock and return the span of the stock's price for the current day. Span of the stock's price today is defined as the maximum number of consecutive days (starting from today and going backwards) for which the price of the stock was less than or equal to today's price. For example, if the price of a stock over the next 7 days were [100, 80, 60, 70, 60, 75, 85], then the stock spans would be [1, 1, 1, 2, 1, 4, 6]. (Solution)

  • Find leaders : An element is leader if it is greater than all the elements to its right side, rightmost element is always a leader. (Solution)

  • Interval List Intersections : Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order. Return the intersection of these two interval lists. Ref. (Solution in ruby), (Solution in java)

  • Search Insert Position Given a sorted array and a target value, return the index if the target is found otherwise return the index where it would be if it were inserted in order ref. Solution

  • H-Index II Given an array of citations sorted in ascending order of a researcher, write a function to compute the researcher's h-index, ref. (solution)

  • Avoid Flood in The City full details

  • Largest Divisible Subset - solution

  • Top K Frequent Elements - solution

  • Given a sorted and rotated array, find if there is a pair with a given sum (ref)

  • Sort elements by frequency (ref). solution

  • Sort a nearly sorted (or K sorted) array (ref). solution

  • Duplicates in an array : Given an array containing elements from 0 to n-1, with any of these numbers appearing any number of times, find these repeating numbers in O(n) and using only constant memory space. (ref). solution

  • Relative Sorting : Sort A1 in such a way that the relative order among the elements will be same as those in A2. For the elements not present in A2, append them at last in sorted order (ref). solution

  • Pythagorean Triplet (ref). solution

  • Chocolate Distribution Problem (ref). solution

  • Stock buy and sell (ref). solution

  • Largest Number formed from an Array (ref). solution

  • Merge k sorted arrays (ref). solution

  • Trapping Rain Water (ref):

  • Find the minimum element in a sorted and rotated array (ref).

Linked List

Tree

valid_path.rb

  • Maximum width of a binary tree. (Solution)

  • A program to check if a binary tree is BST or not. (Solution)

  • Height of Binary Tree. (Solution)

  • Binary Search Tree - Search and Insertion (Solution)

  • Print left view of Binary tree (Solution)

  • Construct bst from preorder traversal (Solution)

  • Diameter of Binary Tree : Diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root. (Solution)

  • Convert a Binary Tree into its Mirror Tree. Also known as Invert Binary Tree (Solution)

  • Root to leaf path sum equal to a given number (Solution)

  • Check if tree is Symmetric i.e. mirror image of itself (Solution)

  • Double Tree (Solution)

  • Cousins in Binary Tree (ref). Solution

  • Maximum Path Sum from one leaf node to another of a binary tree. (ref).

  • Convert a given Binary Tree to Doubly Linked List in-place, ref

  • Given a complete binary tree, count the number of nodes, ref. (solution)

  • Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number, ex: path 1->2->3 represents the number 123. Find the total sum of all root-to-leaf numbers ref. (solution)

  • Maximum difference between node and its ancestor in Binary Tree, ref. (solution)

  • Lowest Common Ancestor in a BST, assuming both the values exist in the tree. solution

  • Vertical Order Traversal of a Binary Tree, (ref).

  • Path Sum III Each node of the tree contains an integer value, find the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it must go downwards, (ref). solution

  • Delete Node in a BST (ref). solution

  • Check if a binary tree is subtree of another binary tree (ref). solution

  • Preorder to Postorder : Given an array of N nodes representing preorder traversal of BST, print its postorder traversal in O(N) time (ref). solution

  • Find k-th smallest element in BST (Order Statistics in BST) (ref). solution

  • Reverse Level Order Traversal (ref). solution

  • Bottom View of Binary Tree (ref). solution

  • Check if given Binary Tree is Height Balanced or Not (details). solution

  • Boundary Traversal of binary tree (details). solution

String

  • Backspace String Compare: Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character. (Solution)

  • Perform String shifts: given list of pairs [direction, amount] to perform shift on a given string. direction 0 means left shift and 1 means right shift. (Solution)

  • Group Anagrams: given an array of strings, group anagrams together. (Solution)

  • Valid Parenthesis String string has 3 types of characters: (, ) and *. * can be treated as ( or ) or empty string. (Solution)

  • Balanced parenthesis : determine if are the parenthesis balanced in a given string

  • Find All Anagrams in a String (ref). Solution

  • Recursively remove all adjacent duplicates (ref). Solution

  • Making File Names Unique Given a list of names, create n folders in your file system such that, create a folder for every name. Since two files cannot have the same name, if you enter a folder name which is previously used, the system will have a suffix addition to its name in the form of (k), where, k is the smallest positive integer such that the obtained name remains unique, ref. (solution)

  • Reverse words in a string OR reverse string word by word

  • Partition Labels : partition the given string into as many parts(groups) as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts. For example: for string "ababcbacadefegdehijhklij" result would be [9,7,8] (ref). solution

  • Roman Number to Integer. solution

  • Longest Palindrome in a String (ref).

  • Length of the longest substring without repeating characters (ref). solution

Sortings

Stack

  • Min Stack : Design a stack that supports push, pop, top, and retrieving the minimum element in constant time (details). (Solution)

  • Infix to Postfix ref. (solution)

  • Evaluation of Postfix Expression ex: '1 2 3 + * 8 -' => -3, ref. (solution)

  • Next Greater Element ref). solution

Matrix / 2D

Advance Data Structures

  • Trie operations with prefix search i.e. insert, search, starts_with, ref. (Solution)

  • Add and Search Word - Data structure design, (ref). solutuon

  • Auto-complete feature using Trie. solution

  • Stream of Characters, (details). solution

DP

  • Making Change Given an amount and coins, write a function to compute the minimum number of coins required to make that amount of change.

  • 0-1 Knapsack You have a knapsack which can carry a certain maximum amount of weight and you have a set of items with their own weight and a monetary value. You can only carry what fits in the knapsack. Find the maximize amount of money that you can earn.

  • Paint House III Given an array houses, an m * n matrix cost and an integer target, return minimum cost of painting all the remaining houses in such a way that there are exactly target neighborhoods, if not possible return -1 (ref)

  • Target Sum Given a list of non-negative numbers and a target, S. Find the number of ways that we can add and subtract the values in nums to add up to T (ref).

  • Coin Change 2 Find number of combinations that make up that amount, assume that you have infinite coins (ref).

  • Find maximum possible stolen value from houses (ref). solution

  • Word Break II Given a non-empty string s and a dictionary wordDict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences, ref. solution

  • Longest Common Substring ref.

Bit Manipulation

  • The Hamming distance between two integers is the number of positions at which the corresponding bits are different, ref. (solution)

  • Position of first set bit found from right side in the binary representation of given the number. (solution)

  • Find most significant set bit of a number. (solution)

Recursion

Bacltracking

  • Word Search from a 2D board of characters, (ref). solution

  • Print all distinct permutations of a given string. (solution)

Misc

Leetcode

ds-algo's People

Contributors

manoj2411 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.