Git Product home page Git Product logo

30-days-dsa-challenge's Introduction

30-Days-DSA-Challenge

Getting into Data Structure And Algorithms May Look Challenging.

This is why this repository is here to help you with DSA problems and solutions to solve them.

How To Get Started

Problems are gotten from Leetcode, Hackerrank and other DSA platforms and structured to help you quickly find them.

  • find a related problem
  • Select the language you want to use in solving the problem
  • you'll find the code, a screenshot and a readMe containing the problem statement

Contributors

Happy Coding

30-days-dsa-challenge's People

Contributors

accodes21 avatar ahlyab avatar aryprogrammer avatar astha369 avatar dhandeep10 avatar dhavisco avatar divyansh14kr avatar f88083 avatar gyanthakur avatar harikrishna-28 avatar iamakashrout avatar iamdestinychild avatar jd2r avatar modernbeast02 avatar nabhia avatar nazeer-18 avatar nitish36 avatar pathakharsh123 avatar petsamuel avatar poornesh-chenna avatar pranee17 avatar reyghosa avatar sanchita1304 avatar sharmavikas4 avatar sidak2002 avatar sravangorati2001 avatar sudhanshujoshi09 avatar usmanbvp avatar yash0605 avatar zainabmalik5 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

Watchers

 avatar

30-days-dsa-challenge's Issues

Binary tree inorder traversal

Description

given the root node return the inorder traversal of it using recursion.

DSA Problem

The issue is to solve the problem of finding inorder traversal of binary tree in c++.

Find Peak Element in Array

Description

A peak element is an element that is strictly greater than its neighbors.

Given a 0-indexed integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.

You may imagine that nums[-1] = nums[n] = -∞. In other words, an element is always considered to be strictly greater than a neighbor that is outside the array.

DSA Problem

Peak Element in Array

Find the Maximum Achievable Number

Description

You are given two integers, num and t.

An integer x is called achievable if it can become equal to num after applying the following operation no more than t times:

Increase or decrease x by 1, and simultaneously increase or decrease num by 1.
Return the maximum possible achievable number. It can be proven that there exists at least one achievable number.

DSA Problem

Above mentioned problem is related to mathematical computation algorithm

Contains Duplicate Problem

Description

You are given an integer array nums and two integers indexDiff and valueDiff.

Find a pair of indices (i, j) such that:

i != j,
abs(i - j) <= indexDiff.
abs(nums[i] - nums[j]) <= valueDiff, and
Return true if such pair exists or false otherwise.

DSA Problem

Find Duplicate Pair with Conditions

Merge k Sorted Lists

Description

You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.

Merge all the linked-lists into one sorted linked-list and return it.

DSA Problem

Merge k Sorted Lists

[Solution] -Leetcode Two Sum in C++

Description

1. Two Sum

The problem asks for two indices in an array of integers such that the elements at these indices add up to a given target value. The initial thought is to use a hash table (unordered_map in C++) to keep track of elements and their indices while iterating through the array. This approach allows us to efficiently check if a complement (the value needed to reach the target) exists in the array.

DSA Problem

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
You can return the answer in any order.

Example 1:
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].

747. Largest Number At Least Twice of Others

Description

This is a leetcode problem.

DSA Problem

Problem:
You are given an integer array nums where the largest integer is unique.

Determine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, or return -1 otherwise.

Solved using Java.

3Sum

Description

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Notice that the solution set must not contain duplicate triplets.

Example 1:

Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]
Explanation:
nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.
nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.
The distinct triplets are [-1,0,1] and [-1,-1,2].
Notice that the order of the output and the order of the triplets does not matter.

DSA Problem

Link: 3Sum

Reverse Linked List

Description

leetcode - 206

DSA Problem

Given the head of a singly linked list, reverse the list, and return the reversed list.

reversell

This is a famous interview question asked in many interviews. Please assign, I would like to contribute to this

11. Container With Most Water

Description

Leetcode problems

DSA Problem

Given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).

Find two lines that together with the x-axis form a container, such that the container contains the most water.

Return the maximum amount of water a container can store.

Notice that you may not slant the container.

Language Used - Python3

Different Ways to Add Parentheses

DESCRIPTION

Given a string expression of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. You may return the answer in any order.

The test cases are generated such that the output values fit in a 32-bit integer and the number of different results does not exceed 104.

Example 1:

Input: expression = "2-1-1"
Output: [0,2]
Explanation:
((2-1)-1) = 0
(2-(1-1)) = 2

This is the Leetcode problem.

DSA PROBLEM -
https://leetcode.com/problems/different-ways-to-add-parentheses/

Can you assign this to me?

1373. Maximum Sum BST in Binary Tree

Description

Leetcode Problems

DSA Problem

Given a binary tree root, return the maximum sum of all keys of any sub-tree which is also a Binary Search Tree (BST).

Assume a BST is defined as follows:

  • The left subtree of a node contains only nodes with keys less than the node's key.
  • The right subtree of a node contains only nodes with keys greater than the node's key.
  • Both the left and right subtrees must also be binary search trees.

Language Used - Python3

94. Binary Tree Inorder Traversal

Description

Given the root of a binary tree, return the inorder traversal of its nodes' values.

DSA Problem

This Problem is related to Binary Tree data structure

Concatenation Of Arrays in python

Description

Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed).

Specifically, ans is the concatenation of two nums arrays.

Return the array ans.

Example 1:

Input: nums = [1,2,1]
Output: [1,2,1,1,2,1]
Explanation: The array ans is formed as follows:

  • ans = [nums[0],nums[1],nums[2],nums[0],nums[1],nums[2]]
  • ans = [1,2,1,1,2,1]
    Example 2:

Input: nums = [1,3,2,1]
Output: [1,3,2,1,1,3,2,1]
Explanation: The array ans is formed as follows:

  • ans = [nums[0],nums[1],nums[2],nums[3],nums[0],nums[1],nums[2],nums[3]]
  • ans = [1,3,2,1,1,3,2,1]

Constraints:

n == nums.length
1 <= n <= 1000
1 <= nums[i] <= 1000

DSA Problem

Link: https://leetcode.com/problems/concatenation-of-array/

51. N queens

Description

this is the problem that will help to understand the concept of the backtracking.
The N-Queens puzzle is a classic problem in computer science and mathematics. In this puzzle, the goal is to place N chess queens on an N×N chessboard in such a way that no two queens threaten each other.

DSA Problem

51. N-Queens

Sudoku Solver

Description

Program to solve sudoku puzzle by filling the empty cells

DSA Problem

A sudoku solution must satisfy all of the following rules:

  1. Each of the digits 1-9 must occur exactly once in each row.
  2. Each of the digits 1-9 must occur exactly once in each column.
  3. Each of the digits 1-9 must occur exactly once in each of the 9 3x3 sub-boxes of the grid.
    The '.' character indicates empty cells.

Number-Of-Good-Pairs

  1. NUMBER OF GOOD PAIRS

Given an array of integers nums, return the number of good pairs.

A pair (i, j) is called good if nums[i] == nums[j] and i < j.

Example 1:

Input: nums = [1,2,3,1,1,3]
Output: 4
Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.
Example 2:

Input: nums = [1,1,1,1]
Output: 6
Explanation: Each pair in the array are good.
Example 3:

Input: nums = [1,2,3]
Output: 0

Constraints:

1 <= nums.length <= 100
1 <= nums[i] <= 100

I WANT TO CONTRIBUTE THE SOLUTION OF THIS ABOVE MENTIONED QUESTION SO PLEASE ASSIGN ME THIS WITH HACKTOBERFEST TAG ON IT.

Topological Sort using BFS in C++

Description

The problem requires us to find topological sort to see if we can take all the courses or not because we need to take one course to take another one.

DSA Problem

Course Schedule 2

Zigzag Conversion

Description

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

P A H N
A P L S I I G
Y I R
And then read line by line: "PAHNAPLSIIGYIR"

Write the code that will take a string and make this conversion given a number of rows:

string convert(string s, int numRows);

Example 1:

Input: s = "PAYPALISHIRING", numRows = 3
Output: "PAHNAPLSIIGYIR"

DSA Problem

Link: Zigzag Conversion

239. Sliding Window Maximum

Description

You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.

Return the max sliding window.

DSA Problem

239. Sliding Window Maximum

[Solution] -Leetcode 35. Search Insert Position in C++

Description

35. Search Insert Position

The problem requires finding the index at which a target value should be inserted into a sorted array of distinct integers while maintaining the sorted order. If the target is already in the array, we return its index. the thought is to use a binary search algorithm to efficiently find the insertion point.

The problem will be solved in C++ programming language.

DSA Problem

Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You must write an algorithm with O(log n) runtime complexity.

Example 1:
Input: nums = [1,3,5,6], target = 5
Output: 2

Example 2:
Input: nums = [1,3,5,6], target = 2
Output: 1

Example 3:
Input: nums = [1,3,5,6], target = 7
Output: 4

Trapping Rain Water

Description

This is a hard level difficulty problem on leetcode

DSA Problem

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining

[Feature]: Implement the GitHub workflow.

GitHub Actions is a versatile tool that can be used to automate a wide range of tasks. It is a powerful tool that can help you to improve the efficiency and quality of your codes.

Product of Array Except Self

Description

This is a Leetcode question

DSA Problem

Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].

The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.

You must write an algorithm that runs in O(n) time and without using the division operation.

Example 1:

Input: nums = [1,2,3,4]
Output: [24,12,8,6]
Example 2:

Input: nums = [-1,1,0,-3,3]
Output: [0,0,9,0,0]

Constraints:

2 <= nums.length <= 105
-30 <= nums[i] <= 30
The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.

Follow up: Can you solve the problem in O(1) extra space complexity? (The output array does not count as extra space for space complexity analysis.)

Merge Two Sorted Lists

Description

You are given the heads of two sorted linked lists list1 and list2.

Merge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists.

Return the head of the merged linked list.

merge_ex1

Example 1:

Input: list1 = [1,2,4], list2 = [1,3,4]
Output: [1,1,2,3,4,4]

DSA Problem

Link: Merge Two Sorted Lists

410. Split Array Largest Sum

Description

This is a leetcode problem

DSA Problem

Given an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized.

Return the minimized largest sum of the split.

A subarray is a contiguous part of the array.

Approach: Solved using binary search

Updating Contribution.md

Description

I am adding more context to the contribution.md file to make things clear for the contributors

DSA Problem

Contribution.md file out of context

Code

No response

150. Evaluate Reverse Polish Notation

Description

You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation.

Evaluate the expression. Return an integer that represents the value of the expression.

Note that:

  • The valid operators are '+', '-', '*', and '/'.
  • Each operand may be an integer or another expression.
  • The division between two integers always truncates toward zero.
  • There will not be any division by zero.
  • The input represents a valid arithmetic expression in a reverse polish notation.
  • The answer and all the intermediate calculations can be represented in a 32-bit integer.

DSA Problem

https://leetcode.com/problems/evaluate-reverse-polish-notation/description/

Regular Expression Matching

Description

Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where:

'.' Matches any single character.​​​​
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).

Example 1:

Input: s = "aa", p = "a"
Output: false
Explanation: "a" does not match the entire string "aa".

DSA Problem

Link: Regular Expression Matching

542. 01 Matrix

Description

Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell.
The distance between two adjacent cells is 1.

Example 1

image

Input: mat = [[0,0,0],[0,1,0],[0,0,0]]
Output: [[0,0,0],[0,1,0],[0,0,0]]

Example 2

image

Input: mat = [[0,0,0],[0,1,0],[1,1,1]]
Output: [[0,0,0],[0,1,0],[1,2,1]]

DSA Problem

https://leetcode.com/problems/01-matrix/description/

69. Sqrt(x)

Description

This is a leetcode problem.

DSA Problem

Problem Description:
Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well.

Solved using binary search approach

monotonic array

Description

This is a leetcode problem. I wish to contribute this problem in your repo. so assign this issue under hacktoberfest label.

DSA Problem

Monotonic Array Problem

[Solution] -Leetcode Two Sum in python

Description

  • The twoSum() method takes two arguments: the input array (nums) and the target sum (target).

  • For each element (num) in the input array, the method calculates the complement (complement) of that element._

  • The method checks if the complement is already in the hash table (container). If it is, then the method returns the indices of the two elements (container[complement] and i).

  • Otherwise, the method adds the element to the hash table (container[num] = i).

DSA Problem

class Solution(object):
    def twoSum(self, nums, target):

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

You can return the answer in any order.

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.