Skip to content

rishimule/leetcode-solutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

336 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode Solutions

Welcome to my LeetCode solutions repository! This repository contains my solutions to various LeetCode problems, categorized by difficulty and topic. The solutions are implemented in multiple programming languages, including Python, Java, and SQL

Table of Contents

Getting Started

To get started with the solutions, simply clone this repository to your local machine:

git clone https://github.com/rishimule/leetcode-solutions.git

Solution Format

Each solution is organized in a separate file named after the problem title, following this format:

<Problem_Title>.<language_extension>

Example Structure

/2191-sort-the-jumbled-numbers
  ├── 2191-sort-the-jumbled-numbers.py  <!-- Example solution file for Sort the Jumbled Numbers problem in Python -->
  ├── README.md  <!-- Problem Description -->

Example Problem

Problem: Sort the Jumbled Numbers problem in Python

  • Link: Sort the Jumbled Numbers problem in Python
  • Description: You are given a 0-indexed integer array mapping which represents the mapping rule of a shuffled decimal system. mapping[i] = j means digit i should be mapped to digit j in this system. The mapped value of an integer is the new integer obtained by replacing each occurrence of digit i in the integer with mapping[i] for all 0 <= i <= 9. You are also given another integer array nums. Return the array nums sorted in non-decreasing order based on the mapped values of its elements.

Solution (Python)

class Solution:
    def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
        def translate_integer(num: int) -> int:
            digits: list[str] = list(str(num))
            for i in range(len(digits)):
                digits[i] = str(mapping[int(digits[i])])
            return int("".join(digits))

        number_mapping: dict[int, int] = {}
        for num in nums:
            number_mapping[num] = translate_integer(num)
        nums.sort(key=lambda val: number_mapping[val])

        return nums

Usage

mapping = [8,9,4,0,2,1,3,5,7,6]
nums = [991,338,38]

s = Solution()
output = s.sortJumbled(mapping, nums)

print(output)  # Output: [338, 38, 991]  <!-- Expected output -->

Contributing

Contributions are welcome! If you have solved a problem that is not yet included in this repository, please feel free to submit a pull request with your solution.

License

This project is licensed under the MIT License - see the LICENSE file for details.

LeetCode Topics

Two Pointers

0005-longest-palindromic-substring
0011-container-with-most-water
0042-trapping-rain-water
0141-linked-list-cycle
0160-intersection-of-two-linked-lists
0611-valid-triangle-number
0647-palindromic-substrings

String

0003-longest-substring-without-repeating-characters
0005-longest-palindromic-substring
0013-roman-to-integer
0072-edit-distance
0139-word-break
0242-valid-anagram
0394-decode-string
0647-palindromic-substrings
1047-remove-all-adjacent-duplicates-in-string
1209-remove-all-adjacent-duplicates-in-string-ii
1347-minimum-number-of-steps-to-make-two-strings-anagram

Dynamic Programming

0005-longest-palindromic-substring
0042-trapping-rain-water
0062-unique-paths
0063-unique-paths-ii
0072-edit-distance
0121-best-time-to-buy-and-sell-stock
0139-word-break
0647-palindromic-substrings
0746-min-cost-climbing-stairs

Hash Table

0003-longest-substring-without-repeating-characters
0013-roman-to-integer
0128-longest-consecutive-sequence
0133-clone-graph
0139-word-break
0141-linked-list-cycle
0146-lru-cache
0160-intersection-of-two-linked-lists
0242-valid-anagram
0268-missing-number
0347-top-k-frequent-elements
0380-insert-delete-getrandom-o1
1347-minimum-number-of-steps-to-make-two-strings-anagram
3507-minimum-pair-removal-to-sort-array-i

Depth-First Search

0098-validate-binary-search-tree
0104-maximum-depth-of-binary-tree
0117-populating-next-right-pointers-in-each-node-ii
0133-clone-graph
0200-number-of-islands
0226-invert-binary-tree
0235-lowest-common-ancestor-of-a-binary-search-tree
0430-flatten-a-multilevel-doubly-linked-list
0695-max-area-of-island

Breadth-First Search

0102-binary-tree-level-order-traversal
0104-maximum-depth-of-binary-tree
0117-populating-next-right-pointers-in-each-node-ii
0133-clone-graph
0200-number-of-islands
0226-invert-binary-tree
0695-max-area-of-island
0994-rotting-oranges

Graph

0133-clone-graph

Array

0004-median-of-two-sorted-arrays
0011-container-with-most-water
0039-combination-sum
0042-trapping-rain-water
0056-merge-intervals
0063-unique-paths-ii
0078-subsets
0121-best-time-to-buy-and-sell-stock
0128-longest-consecutive-sequence
0136-single-number
0139-word-break
0153-find-minimum-in-rotated-sorted-array
0200-number-of-islands
0268-missing-number
0347-top-k-frequent-elements
0380-insert-delete-getrandom-o1
0611-valid-triangle-number
0695-max-area-of-island
0746-min-cost-climbing-stairs
0875-koko-eating-bananas
0994-rotting-oranges
1029-two-city-scheduling
1472-design-browser-history
1823-find-the-winner-of-the-circular-game
2943-maximize-area-of-square-hole-in-grid
3147-taking-maximum-energy-from-the-mystic-dungeon
3507-minimum-pair-removal-to-sort-array-i

Greedy

0011-container-with-most-water
0611-valid-triangle-number
1029-two-city-scheduling

Trie

0139-word-break

Memoization

0139-word-break

Linked List

0002-add-two-numbers
0021-merge-two-sorted-lists
0117-populating-next-right-pointers-in-each-node-ii
0141-linked-list-cycle
0146-lru-cache
0160-intersection-of-two-linked-lists
0430-flatten-a-multilevel-doubly-linked-list
1472-design-browser-history
3507-minimum-pair-removal-to-sort-array-i

Math

0002-add-two-numbers
0007-reverse-integer
0009-palindrome-number
0013-roman-to-integer
0050-powx-n
0062-unique-paths
0268-missing-number
0380-insert-delete-getrandom-o1
1823-find-the-winner-of-the-circular-game

Binary Search

0004-median-of-two-sorted-arrays
0153-find-minimum-in-rotated-sorted-array
0268-missing-number
0611-valid-triangle-number
0875-koko-eating-bananas

Bit Manipulation

0078-subsets
0136-single-number
0268-missing-number

Sorting

0056-merge-intervals
0242-valid-anagram
0268-missing-number
0347-top-k-frequent-elements
0611-valid-triangle-number
1029-two-city-scheduling
2943-maximize-area-of-square-hole-in-grid

Stack

0042-trapping-rain-water
0155-min-stack
0394-decode-string
1047-remove-all-adjacent-duplicates-in-string
1209-remove-all-adjacent-duplicates-in-string-ii
1472-design-browser-history

Monotonic Stack

0042-trapping-rain-water

Design

0146-lru-cache
0155-min-stack
0380-insert-delete-getrandom-o1
1472-design-browser-history

Randomized

0380-insert-delete-getrandom-o1

Union Find

0200-number-of-islands

Matrix

0063-unique-paths-ii
0200-number-of-islands
0695-max-area-of-island
0994-rotting-oranges

Doubly-Linked List

0146-lru-cache
0430-flatten-a-multilevel-doubly-linked-list
1472-design-browser-history
3507-minimum-pair-removal-to-sort-array-i

Sliding Window

0003-longest-substring-without-repeating-characters

Recursion

0002-add-two-numbers
0021-merge-two-sorted-lists
0050-powx-n
0394-decode-string
1823-find-the-winner-of-the-circular-game

Tree

0098-validate-binary-search-tree
0102-binary-tree-level-order-traversal
0104-maximum-depth-of-binary-tree
0117-populating-next-right-pointers-in-each-node-ii
0226-invert-binary-tree
0235-lowest-common-ancestor-of-a-binary-search-tree

Binary Search Tree

0098-validate-binary-search-tree
0235-lowest-common-ancestor-of-a-binary-search-tree

Binary Tree

0098-validate-binary-search-tree
0102-binary-tree-level-order-traversal
0104-maximum-depth-of-binary-tree
0117-populating-next-right-pointers-in-each-node-ii
0226-invert-binary-tree
0235-lowest-common-ancestor-of-a-binary-search-tree

Queue

1823-find-the-winner-of-the-circular-game

Simulation

1823-find-the-winner-of-the-circular-game
3507-minimum-pair-removal-to-sort-array-i

Heap (Priority Queue)

0347-top-k-frequent-elements
3507-minimum-pair-removal-to-sort-array-i

Ordered Set

3507-minimum-pair-removal-to-sort-array-i

Prefix Sum

3147-taking-maximum-energy-from-the-mystic-dungeon

Divide and Conquer

0004-median-of-two-sorted-arrays
0347-top-k-frequent-elements

Combinatorics

0062-unique-paths

Counting

0347-top-k-frequent-elements
1347-minimum-number-of-steps-to-make-two-strings-anagram

Backtracking

0039-combination-sum
0078-subsets

Union-Find

0128-longest-consecutive-sequence
0695-max-area-of-island

Data Stream

1472-design-browser-history

Bucket Sort

0347-top-k-frequent-elements

Quickselect

0347-top-k-frequent-elements

About

A public repository to store and share solutions to LeetCode problems. This repository includes various algorithms and data structures implemented in multiple programming languages.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages