Git Product home page Git Product logo

dheeraj-2000 / dsalgo Goto Github PK

View Code? Open in Web Editor NEW
84.0 2.0 382.0 4.69 MB

Contains Algorithms useful for interview preparation, various practice problems of Arrays, Stacks, queue etc. Contributors are Welcome but, DO NOT MAKE THIS REPO ACT LIKE A SOURCE OF +1.

C++ 72.02% Python 8.15% Java 10.18% C 9.42% JavaScript 0.21% Kotlin 0.02%
algorithms firstpullrequest interview-practice arrays hacktoberfest hacktoberfest2022

dsalgo's Introduction

Update: Please read this before moving ahead Important!

How to contribute ?

  • Have a look at open issues, they contain the list of algorithms/DS we plan to be implemented.
  • You can also create a new issue for an algorithm that is not in the list.
  • Fork the repository.
  • Clone the repo. to your local system.
  • Add the algorithms/codes that you want to contribute (and properly rename you algorithm/code, also if possible keep in the respective folder)
  • Make another Development branch. (Apart from main branch).
  • Open the pull request.
  • Resolve conflicts ( if any ).
  • Wait for the pull request to be approved.

Code I expect (for everyone):

  • Add relevant comments explaining what the code is all about (if possible write the Time and Space complexities)
  • It should be properly formatted and indented
  • Please use proper naming for variables, do not use i,j,k,x,y,z. The variable name should be self explanatory.
  • Use proper names for your files.
  • Do all your changes in your forked repository branch and not in master branch untill asked.
  • I will reject any pull request which looks like spammy or just to have +1 in the counter, so contribute quality code here!
  • As per guidlines of Hacktoberfest, I will not merge any plagrised code or any type of fishy code.

Feel free to contact, if you face any issue in contributing to Open Source

LinkedIn   Instagram   Twitter  

Thanks to all Contributors

***

Made with ❤️ by DHEERAJ

dsalgo's People

Contributors

ag278 avatar ag41-tech avatar akhilaku avatar akhilesh59 avatar akshad7829 avatar altctrldel1999 avatar ankita413 avatar ankitdimri avatar coderider686 avatar dheeraj-2000 avatar dish26 avatar elismar13 avatar ewei068 avatar gaurav-baghel avatar gaurisha21 avatar mp3730 avatar prachi-2001 avatar rohanmahto592 avatar saikumar010 avatar sanchman21 avatar sanjana1391 avatar sanjaydogood avatar sarvjeetdev avatar sejal1126 avatar shrishtisrivastava avatar shubhamghule1 avatar srishti-ahuja avatar sultanarif-p avatar sultanrif avatar vikashpatel07 avatar

Stargazers

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

Watchers

 avatar  avatar

dsalgo's Issues

UPDATED: An update on efforts to reduce spam with Hacktoberfest: introducing maintainer opt-in and more.

Hello everyone

You might be aware that a lot of spamming is happening this year, and this has totally disturbed the Open Source community. So new ways has been added to discourage participants from spamming, which were intended to just +1 their PR count, Major updates are:

  • Repository classified with the ‘hacktoberfest’ topic: Now onwards, only the repositories which have this topic will be eligible for hacktoberfest contribution.
  • The pull requests will also need to be merged, approved by a maintainer, or labeled as ‘hacktoberfest-accepted’ in order to qualify. The deadline for completions, merging, labeling, and approving is November 1.

Read full UPDATE here

Thanks
Happy coding ✌️

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 is able to trap after raining.

Examples:

Input: arr[] = {2, 0, 2}
Output: 2
Kindly assign this issue to me......

Prim Algorithm

I would like to work on this issue.In this I explain my code with understandable comments and with proper input and output Format.
Please assign it to me @dheeraj-2000

Egg Dropping Puzzle

The following is a description of the instance of this famous puzzle involving n=2 eggs and a building with k=36 floors.
Suppose that we wish to know which stories in a 36-story building are safe to drop eggs from, and which will cause the eggs to break on landing. We make a few assumptions:
…..An egg that survives a fall can be used again.
…..A broken egg must be discarded.
…..The effect of a fall is the same for all eggs.
…..If an egg breaks when dropped, then it would break if dropped from a higher floor.
…..If an egg survives a fall then it would survive a shorter fall.
…..It is not ruled out that the first-floor windows break eggs, nor is it ruled out that the 36th-floor do not cause an egg to break.
If only one egg is available and we wish to be sure of obtaining the right result, the experiment can be carried out in only one way. Drop the egg from the first-floor window; if it survives, drop it from the second-floor window. Continue upward until it breaks. In the worst case, this method may require 36 droppings. Suppose 2 eggs are available. What is the least number of egg-droppings that is guaranteed to work in all cases?

Kindly assign this issue to me.........

Median of two sorted arrays(Leetcode Solution)

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

The overall run time complexity should be O(log (m+n)).

Example 1:

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

Input: nums1 = [1,2], nums2 = [3,4]
Output: 2.50000
Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.

Constraints:

nums1.length == m
nums2.length == n
0 <= m <= 1000
0 <= n <= 1000
1 <= m + n <= 2000
-106 <= nums1[i], nums2[i] <= 106

Added Prime Factorization of Number

I have raised PR #337 for prime factorization of the number ,
finding the number of divisors of number and the sum of all divisors.
Please review it and accept it.

⚠️ Disclaimer

  • This repo welcome beginners to Github and the opensource community by helping them learn how to make contributions to open source!

  • As said, only high-quality contributions and pull requests that add value to Open Source projects are part of the core values of Hacktoberfest. So, my priority is quality of contribution over quantity and that's what I expect from you as a contributor.

  • Therefore, I highly recommend you to contribute in a meaningful way in this repository and other Hacktoberfest issues by following the guidlines of the repos.

⚠️ Please refrain plagiarising code for the sake of pull request. I highly discourage it

Rotate List

I would like to contribute the code to rotate a linked list to the right by k places. Please assign this issue to me under hacktoberfest 2022

Dice Throw

Given n dice each with m faces, numbered from 1 to m, find the number of ways to get sum X. X is the summation of values on each face when all the dice are thrown.

Kindly assign this issue to me........

Longest Repeating Subsequence using DP

Hi @dheeraj-2000
I would like to write a code for the Longest Repeating Subsequence Problem. In this problem Given a string, find the length of longest repeating subsequence such that two subsequences don't have same string character at same position.. I will implement it using Dynamic Programming in C++ with proper comments and explanation of the code.

Pots of Gold Game

Two players X and Y are playing a game in which there are pots of gold arranged in a line, each containing some gold coins. They get alternating turns in which the player can pick a pot from one of the ends of the line. The winner is the player who has a higher number of coins at the end. The objective is to maximize the number of coins collected by X, assuming Y also plays optimally.

Return the maximum coins X could get while playing the game. Initially, X starts the game.
Example 1:

Input:
N = 4
Q[] = {8, 15, 3, 7}
Output: 22
Explanation: Player X starts and picks 7. Player Y
picks the pot containing 8. Player X picks the pot
containing 15. Player Y picks 3.
Total coins collected by X = 7 + 15 = 22.
Kindly assign this issue to me......

Longest Common Prefix - String DSA

Hey there, I'm participating in #hactoberfest2k21, Please assign me the issue. Good day!
Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string "".
Example:
Input: strs = ["flower","flow","flight"]
Output: "fl"

Longest Common Substring DP problem

Hi @dheeraj-2000
I would like to write a code for the Longest Common Substring Problem. In this problem we have to determine the length of longest common substring between two given strings. I will implement it using Dynamic Programming in C++ with proper comments and explanation of the code.

Add Integer Break

I have added Integer Break which is a Leetcode problem in this PR #244
Kindly review it.
Thanks

DSA-Array-Python-Merge Intervals

Hey there, I'm participating in #hactoberfest2k21, Please assign me the issue. Good day!
Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.
Example:
Input: intervals = [[1,3],[2,5]]
Output: [[1,5]]

Moore's Voting Algorithm to find the majority element in an array.

Please consider this as my contribution towards Hacktoberfest 2022. I would be really grateful to you. I am living for that t-shirt.

I commented every step in order to make the code more readable and understandable.

#include<bits/stdc++.h>
using namespace std;

int moore_voting(int [], int);

int main()
{
    int n, ar[50];
    cout << "Enter the size of the array: ";
    cin >> n;
    for(int i = 0; i<n; i++)
    {
        cout << "ar[" << i << "] = ";
        cin >> ar[i];
    }
    cout << "The majority element in the array is: ";
    cout << moore_voting(ar, n);
}

int moore_voting(int arr[], int size)
{
    //Phase 1: - Finds a suitable candidate for the majority element
    int res = 0, count = 1;     //
    for(int i = 1; i<size; i++)    //Traversing the array
    {
        if(arr[res] == arr[i])   //Checking if first element is same as ith element
            count++;     //If yes then incrementing the count by 1
        else
            count--;     //Decrementing the count if ith element is not equal to first element
        if(count==0)     //If at any point the count becomes 0 while decrementing
        {
            res = i;     //Updating the ith element as result since it's not a suitable 
            count = 1;   //candidate for majority. Also resetting the count of majority element
        }
    }

    //Phase 2: - Checks if the candidate selected is actually in majority or not
    count = 0;
    for(int i = 0; i<size; i++)
    {
        if(arr[res] == arr[i])
        
            count++;              //Line 36-44: - Checks if the candidate
    }                             //element is a majority element or not
    if(count <= size/2)
        res = -1;
    return res;
}

Add famous sorting algortihms in C++ language

I would like to add some famous sorting algorithms (many of which work in O(nlogn) time complexity) in the main section of the repository as a part of hacktoberfest 2020. Please assign me this work

Dijkstra’s shortest path algorithm

Given a graph and a source vertex in the graph, find the shortest paths from the source to all vertices in the given graph.

Kindly assign this issue to me.....

Josephus problem

There are n people standing in a circle waiting to be executed. The counting out begins at some point in the circle and proceeds around the circle in a fixed direction. In each step, a certain number of people are skipped and the next person is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom. Given the total number of persons n and a number k which indicates that k-1 persons are skipped and kth person is killed in circle. The task is to choose the place in the initial circle so that you are the last one remaining and so survive.
For example, if n = 5 and k = 2, then the safe position is 3. Firstly, the person at position 2 is killed, then person at position 4 is killed, then person at position 1 is killed. Finally, the person at position 5 is killed. So the person at position 3 survives.
If n = 7 and k = 3, then the safe position is 4. The persons at positions 3, 6, 2, 7, 5, 1 are killed in order, and person at position 4 survives.

Please assign this to me.......

Coin game winner where every player has three choices

A and B are playing a game. At the beginning there are n coins. Given two more numbers x and y. In each move a player can pick x or y or 1 coins. A always starts the game. The player who picks the last coin wins the game or the person who is not able to pick any coin loses the game. For a given value of n, find whether A will win the game or not if both are playing optimally.

Examples: Input : n = 5, x = 3, y = 4
Output : A
There are 5 coins, every player can pick 1 or
3 or 4 coins on his/her turn.
A can win by picking 3 coins in first chance.
Now 2 coins will be left so B will pick one
coin and now A can win by picking the last coin.

Input : 2 3 4
Output : B

Kindly assign this issue to me............

Add Kosaraju's algorithm

I would like to add Kosaraju's algorithm used to identify strongly connected components of a graph under graph section.

Addition of concept of Disjoint Set Union

Addition of DSU concept.

Often it is also called Union Find because of its two main operations.

This data structure provides the following capabilities. We are given several elements, each of which is a separate set. A DSU will have an operation to combine any two sets, and it will be able to tell in which set a specific element is. The classical version also introduces a third operation, it can create a set from a new element.

Thus the basic interface of this data structure consists of only three operations:

make_set(v) - creates a new set consisting of the new element v
union_sets(a, b) - merges the two specified sets (the set in which the element a is located, and the set in which the element b is located)
find_set(v) - returns the representative (also called leader) of the set that contains the element v. This representative is an element of its corresponding set. It is selected in each set by the data structure itself (and can change over time, namely after union_sets calls). This representative can be used to check if two elements are part of the same set or not. a and b are exactly in the same set, if find_set(a) == find_set(b). Otherwise they are in different sets.

I will add a question that involves this concept.
I will update the corresponding PR Number asap.
Please accept my improvement. @dheeraj-2000

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.