├── README.md
├── 135. Candy
├── README.md
└── 135. Candy.cpp
├── 100. Same Tree
├── README.md
└── 100. Same Tree.cpp
├── 112. Path Sum
├── README.md
└── 112. Path Sum.cpp
├── 458. Poor Pigs
├── README.md
└── 458. Poor Pigs.cpp
├── 113. Path Sum II
├── README.md
└── 113. Path Sum II.cpp
├── 133. Clone Graph
├── README.md
└── 133. Clone Graph.cpp
├── 383. Ransom Note
├── README.md
└── 326. Power of Three.cpp
├── 91. Decode Ways
├── README.md
└── 91. Decode Ways.cpp
├── 16. 3Sum Closest
├── README.md
└── 16. 3Sum Closest.cpp
├── 231. Power of Two
├── README.md
└── 231. Power of Two.cpp
├── 38. Count and Say
├── README.md
└── 38. Count and Say.cpp
├── 48. Rotate Image
├── README.md
└── 48. Rotate Image.cpp
├── 62. Unique Paths
├── README.md
└── 62. Unique Paths.cpp
├── 645. Set Mismatch
├── README.md
└── 645. Set Mismatch.cpp
├── 71. Simplify Path
├── README.md
└── 71. Simplify Path.cpp
├── 126. Word Ladder II
├── README.md
└── 126. Word Ladder II.cpp
├── 136. Single Number
├── README.md
└── 136. Single Number.cpp
├── 326. Power of Three
├── README.md
└── 326. Power of Three.cpp
├── 342. Power of Four
├── README.md
└── 342. Power of Four.cpp
├── 39. Combination Sum
├── README.md
└── 39. Combination Sum.cpp
├── 49. Group Anagrams
├── README.md
└── 49. Group Anagrams.cpp
├── 704. Binary Search
├── README.md
└── 704. Binary Search.cpp
├── 729. My Calendar I
├── README.md
└── 729. My Calendar I.cpp
├── 796. Rotate String
├── README.md
└── 796. Rotate String.cpp
├── 835. Image Overlap
├── README.md
└── 835. Image Overlap.cpp
├── 838. Push Dominoes
├── README.md
└── 838. Push Dominoes.cpp
├── 948. Bag of Tokens
├── README.md
└── 948. Bag of Tokens.cpp
├── 1035. Uncrossed Lines
├── README.md
└── 1035. Uncrossed Lines.cpp
├── 12. Integer to Roman
├── README.md
└── 12. Integer to Roman.cpp
├── 13. Roman to Integer
├── README.md
└── 13. Roman to Integer.cpp
├── 336. Palindrome Pairs
├── README.md
└── 336. Palindrome Pairs.cpp
├── 393. UTF-8 Validation
├── README.md
└── 393. UTF-8 Validation.cpp
├── 43. Multiply Strings
├── README.md
└── 43. Multiply Strings.cpp
├── 509. Fibonacci Number
├── README.md
└── 509. Fibonacci Number.cpp
├── 732. My Calendar III
├── README.md
└── 732. My Calendar III.cpp
├── 766. Toeplitz Matrix
├── README.md
└── 766. Toeplitz Matrix.cpp
├── 20. Valid Parentheses
├── README.md
└── 20. Valid Parentheses.cpp
├── 200. Number of Islands
├── README.md
└── 200. Number of Islands.cpp
├── 242. Valid Anagram
├── README.md
└── 242. Valid Anagram.cpp
├── 257. Binary Tree Paths
├── README.md
└── 257. Binary Tree Paths.cpp
├── 858. Mirror Reflection
├── README.md
└── 858. Mirror Reflection.cpp
├── 1020. Number of Enclaves
├── README.md
└── 1020. Number of Enclaves.cpp
├── 1328. Break a Palindrome
├── README.md
└── 1328. Break a Palindrome.cpp
├── 218. The Skyline Problem
├── README.md
└── 218. The Skyline Problem.cpp
├── 29. Divide Two Integers
├── README.md
└── 29. Divide Two Integers.cpp
├── 377. Combination Sum IV
├── README.md
└── 377. Combination Sum IV.cpp
├── 42. Trapping Rain Water
├── README.md
└── 42. Trapping Rain Water.cpp
├── 623. Add One Row to Tree
├── README.md
└── 623. Add One Row to Tree.cpp
├── 814. Binary Tree Pruning
├── README.md
└── 814. Binary Tree Pruning.cpp
├── 219. Contains Duplicate II
├── README.md
└── 219. Contains Duplicate II.cpp
├── 450. Delete Node in a BST
├── README.md
└── 450. Delete Node in a BST.cpp
├── 622. Design Circular Queue
├── README.md
└── 622. Design Circular Queue.cpp
├── 692. Top K Frequent Words
├── README.md
└── 692. Top K Frequent Words.cpp
├── 869. Reordered Power of 2
├── README.md
└── 869. Reordered Power of 2.cpp
├── 1531. String Compression II
├── README.md
└── 1531. String Compression II.cpp
├── 234. Palindrome Linked List
├── README.md
└── 234. Palindrome Linked List.cpp
├── 35. Search Insert Position
├── README.md
└── 35. Search Insert Position.cpp
├── 1480. Running Sum of 1d Array
├── README.md
└── 1480. Running Sum of 1d Array.cpp
├── 196. Delete Duplicate Emails
├── README.md
└── 196. Delete Duplicate Emails.sql
├── 523. Continuous Subarray Sum
├── README.md
└── 523. Continuous Subarray Sum.cpp
├── 658. Find K Closest Elements
├── README.md
└── 658. Find K Closest Elements.cpp
├── 76. Minimum Window Substring
├── README.md
└── 76. Minimum Window Substring.cpp
├── 804. Unique Morse Code Words
├── README.md
└── 804. Unique Morse Code Words.cpp
├── 881. Boats to Save People
├── README.md
└── 881. Boats to Save People.cpp
├── 890. Find and Replace Pattern
├── README.md
└── 890. Find and Replace Pattern.cpp
├── 946. Validate Stack Sequences
├── README.md
└── 946. Validate Stack Sequences.cpp
├── 1220. Count Vowels Permutation
├── README.md
└── 1220. Count Vowels Permutation.cpp
├── 1254. Number of Closed Islands
├── README.md
└── 1254. Number of Closed Islands.cpp
├── 1679. Max Number of K-Sum Pairs
├── README.md
└── 1679. Max Number of K-Sum Pairs.cpp
├── 2439. Minimize Maximum of Array
├── README.md
└── 2439. Minimize Maximum of Array.cpp
├── 349. Intersection of Two Arrays
├── README.md
└── 349. Intersection of Two Arrays.cpp
├── 508. Most Frequent Subtree Sum
├── README.md
└── 508. Most Frequent Subtree Sum.cpp
├── 53. Two Sum IV - Input is a BST
├── README.md
└── 53. Two Sum IV - Input is a BST.cpp
├── 710. Random Pick with Blacklist
├── README.md
└── 710. Random Pick with Blacklist.cpp
├── 823. Binary Trees With Factors
├── README.md
└── 823. Binary Trees With Factors.cpp
├── 936. Stamping The Sequence
├── README.md
└── 936. Stamping The Sequence.cpp
├── 976. Largest Perimeter Triangle
├── README.md
└── 976. Largest Perimeter Triangle.cpp
├── 981. Time Based Key-Value Store
├── README.md
└── 981. Time Based Key-Value Store.cpp
├── 1678. Goal Parser Interpretation
├── README.md
└── 1678. Goal Parser Interpretation.cpp
├── 2405. Optimal Partition of String
├── README.md
└── 2405. Optimal Partition of String.cpp
├── 417. Pacific Atlantic Water Flow
├── README.md
└── 417. Pacific Atlantic Water Flow.cpp
├── 538. Convert BST to Greater Tree
├── README.md
└── 538. Convert BST to Greater Tree.cpp
├── 98. Validate Binary Search Tree
├── README.md
└── 98. Validate Binary Search Tree.cpp
├── 124. Binary Tree Maximum Path Sum
├── README.md
└── 124. Binary Tree Maximum Path Sum.cpp
├── 237. Delete Node in a Linked List
├── README.md
└── 237. Delete Node in a Linked List.cpp
├── 2390. Removing Stars From a String
├── README.md
└── 2390. Removing Stars From a String.cpp
├── 557. Reverse Words in a String III
├── README.md
└── 557. Reverse Words in a String III.cpp
├── 609. Find Duplicate File in System
├── README.md
└── 609. Find Duplicate File in System.cpp
├── 94. Binary Tree Inorder Traversal
├── README.md
└── 94. Binary Tree Inorder Traversal.cpp
├── 1329. Sort the Matrix Diagonally
├── README.md
└── 1329. Sort the Matrix Diagonally.cpp
├── 1338. Reduce Array Size to The Half
├── README.md
└── 1338. Reduce Array Size to The Half.cpp
├── 1383. Maximum Performance of a Team
├── README.md
└── 1383. Maximum Performance of a Team.cpp
├── 1670. Design Front Middle Back Queue
├── README.md
└── 1670. Design Front Middle Back Queue.cpp
├── 300. Longest Increasing Subsequence
├── README.md
└── 300. Longest Increasing Subsequence.cpp
├── 334. Increasing Triplet Subsequence
├── README.md
└── 334. Increasing Triplet Subsequence.cpp
├── 516. Longest Palindromic Subsequence
├── README.md
└── 516. Longest Palindromic Subsequence.cpp
├── 1448. Count Good Nodes in Binary Tree
├── README.md
└── 1448. Count Good Nodes in Binary Tree.cpp
├── 1832. Check if the Sentence Is Pangram
├── README.md
└── 1832. Check if the Sentence Is Pangram.cpp
├── 19. Remove Nth Node From End of List
├── README.md
└── 19. Remove Nth Node From End of List.cpp
├── 429. N-ary Tree Level Order Traversal
├── README.md
└── 429. N-ary Tree Level Order Traversal.cpp
├── 637. Average of Levels in Binary Tree
├── README.md
└── 637. Average of Levels in Binary Tree.cpp
├── 102. Binary Tree Level Order Traversal
├── README.md
└── 102. Binary Tree Level Order Traversal.cpp
├── 188. Best Time to Buy and Sell Stock IV
├── README.md
└── 188. Best Time to Buy and Sell Stock IV.cpp
├── 387. First Unique Character in a String
├── README.md
└── 387. First Unique Character in a String.cpp
├── 871. Minimum Number of Refueling Stops
├── README.md
└── 871. Minimum Number of Refueling Stops.cpp
├── 985. Sum of Even Numbers After Queries
├── README.md
└── 985. Sum of Even Numbers After Queries.cpp
├── 1578. Minimum Time to Make Rope Colorful
├── README.md
└── 1578. Minimum Time to Make Rope Colorful.cpp
├── 1636. Sort Array by Increasing Frequency
├── README.md
└── 1636. Sort Array by Increasing Frequency.cpp
├── 2136. Earliest Possible Day of Full Bloom
├── README.md
└── 2136. Earliest Possible Day of Full Bloom.cpp
├── 501. Find Mode in Binary Search Tree
├── README.md
└── 501. Find Mode in Binary Search Tree.cpp
├── 718. Maximum Length of Repeated Subarray
├── README.md
└── 718. Maximum Length of Repeated Subarray.cpp
├── 990. Satisfiability of Equality Equations
├── README.md
└── 990. Satisfiability of Equality Equations.cpp
├── 1155. Number of Dice Rolls With Target Sum
├── README.md
└── 1155. Number of Dice Rolls With Target Sum.cpp
├── 1335. Minimum Difficulty of a Job Schedule
├── README.md
└── 1335. Minimum Difficulty of a Job Schedule.cpp
├── 363. Max Sum of Rectangle No Larger Than K
├── README.md
└── 363. Max Sum of Rectangle No Larger Than K.cpp
├── 606. Construct String from Binary Tree
├── README.md
└── 606. Construct String from Binary Tree.cpp
├── 2007. Find Original Array From Doubled Array
├── README.md
└── 2007. Find Original Array From Doubled Array.cpp
├── 2300. Successful Pairs of Spells and Potions
├── README.md
└── 2300. Successful Pairs of Spells and Potions.cpp
├── 378. Kth Smallest Element in a Sorted Matrix
├── README.md
└── 378. Kth Smallest Element in a Sorted Matrix.cpp
├── 103. Binary Tree Zigzag Level Order Traversal
├── README.md
└── 103. Binary Tree Zigzag Level Order Traversal.cpp
├── 2095. Delete the Middle Node of a Linked List
├── README.md
└── 2095. Delete the Middle Node of a Linked List.cpp
├── 30. Substring with Concatenation of All Words
├── README.md
└── 30. Substring with Concatenation of All Words.cpp
├── 659. Split Array into Consecutive Subsequences
├── README.md
└── 659. Split Array into Consecutive Subsequences.cpp
├── 967. Numbers With Same Consecutive Differences
├── README.md
└── 967. Numbers With Same Consecutive Differences.cpp
├── 987. Vertical Order Traversal of a Binary Tree
├── README.md
└── 987. Vertical Order Traversal of a Binary Tree.cpp
├── 108. Convert Sorted Array to Binary Search Tree
├── README.md
└── 108. Convert Sorted Array to Binary Search Tree.cpp
├── 1457. Pseudo-Palindromic Paths in a Binary Tree
├── README.md
└── 1457. Pseudo-Palindromic Paths in a Binary Tree.cpp
├── 1662. Check If Two String Arrays are Equivalent
├── README.md
└── 1662. Check If Two String Arrays are Equivalent.cpp
├── 1996. The Number of Weak Characters in the Game
├── README.md
└── 1996. The Number of Weak Characters in the Game.cpp
├── 2114. Maximum Number of Words Found in Sentences
├── README.md
└── 2114. Maximum Number of Words Found in Sentences.cpp
├── 1680. Concatenation of Consecutive Binary Numbers
├── README.md
└── 1680. Concatenation of Consecutive Binary Numbers.cpp
├── 235. Lowest Common Ancestor of a Binary Search Tree
├── README.md
└── 235. Lowest Common Ancestor of a Binary Search Tree.cpp
├── 1293. Shortest Path in a Grid with Obstacles Elimination
├── README.md
└── 1293. Shortest Path in a Grid with Obstacles Elimination.cpp
├── 1770. Maximum Score from Performing Multiplication Operations
├── README.md
└── 1770. Maximum Score from Performing Multiplication Operations.cpp
├── 105. Construct Binary Tree from Preorder and Inorder Traversal
├── README.md
└── 105. Construct Binary Tree from Preorder and Inorder Traversal.cpp
├── 106. Construct Binary Tree from Inorder and Postorder Traversal
├── README.md
└── 106. Construct Binary Tree from Inorder and Postorder Traversal.cpp
├── 1239. Maximum Length of a Concatenated String with Unique Characters
├── README.md
└── 1239. Maximum Length of a Concatenated String with Unique Characters.cpp
├── LICENSE.md
├── Monotonic Renumeration.cpp
├── Water The Trees.cpp
├── AMONGUS2.cpp
└── Balanced Ternary String.cpp
/README.md:
--------------------------------------------------------------------------------
1 | ## Leetcode
2 | My leetcode struggle.
3 |
--------------------------------------------------------------------------------
/135. Candy/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 |
135. Candy
3 |
--------------------------------------------------------------------------------
/100. Same Tree/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 100. Same Tree
3 |
--------------------------------------------------------------------------------
/112. Path Sum/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 112. Path Sum
3 |
--------------------------------------------------------------------------------
/458. Poor Pigs/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 458. Poor Pigs
3 |
--------------------------------------------------------------------------------
/113. Path Sum II/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 113. Path Sum II
3 |
--------------------------------------------------------------------------------
/133. Clone Graph/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 133. Clone Graph
3 |
--------------------------------------------------------------------------------
/383. Ransom Note/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 383. Ransom Note
3 |
--------------------------------------------------------------------------------
/91. Decode Ways/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 91. Decode Ways
3 |
--------------------------------------------------------------------------------
/16. 3Sum Closest/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 16. 3Sum Closest
3 |
--------------------------------------------------------------------------------
/231. Power of Two/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 231. Power of Two
3 |
--------------------------------------------------------------------------------
/38. Count and Say/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 38. Count and Say
3 |
--------------------------------------------------------------------------------
/48. Rotate Image/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 48. Rotate Image
3 |
--------------------------------------------------------------------------------
/62. Unique Paths/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 62. Unique Paths
3 |
--------------------------------------------------------------------------------
/645. Set Mismatch/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 645. Set Mismatch
3 |
--------------------------------------------------------------------------------
/71. Simplify Path/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 71. Simplify Path
3 |
--------------------------------------------------------------------------------
/126. Word Ladder II/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 126. Word Ladder II
3 |
--------------------------------------------------------------------------------
/136. Single Number/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 136. Single Number
3 |
--------------------------------------------------------------------------------
/326. Power of Three/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 326. Power of Three
3 |
--------------------------------------------------------------------------------
/342. Power of Four/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 342. Power of Four
3 |
--------------------------------------------------------------------------------
/39. Combination Sum/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 39. Combination Sum
3 |
--------------------------------------------------------------------------------
/49. Group Anagrams/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 49. Group Anagrams
3 |
--------------------------------------------------------------------------------
/704. Binary Search/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 704. Binary Search
3 |
--------------------------------------------------------------------------------
/729. My Calendar I/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 729. My Calendar I
3 |
--------------------------------------------------------------------------------
/796. Rotate String/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 796. Rotate String
3 |
--------------------------------------------------------------------------------
/835. Image Overlap/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 835. Image Overlap
3 |
--------------------------------------------------------------------------------
/838. Push Dominoes/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 838. Push Dominoes
3 |
--------------------------------------------------------------------------------
/948. Bag of Tokens/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 948. Bag of Tokens
3 |
--------------------------------------------------------------------------------
/1035. Uncrossed Lines/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1035. Uncrossed Lines
3 |
--------------------------------------------------------------------------------
/12. Integer to Roman/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 12. Integer to Roman
3 |
--------------------------------------------------------------------------------
/13. Roman to Integer/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 13. Roman to Integer
3 |
--------------------------------------------------------------------------------
/336. Palindrome Pairs/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 336. Palindrome Pairs
3 |
--------------------------------------------------------------------------------
/393. UTF-8 Validation/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 393. UTF-8 Validation
3 |
--------------------------------------------------------------------------------
/43. Multiply Strings/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 43. Multiply Strings
3 |
--------------------------------------------------------------------------------
/509. Fibonacci Number/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 509. Fibonacci Number
3 |
--------------------------------------------------------------------------------
/732. My Calendar III/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 732. My Calendar III
3 |
--------------------------------------------------------------------------------
/766. Toeplitz Matrix/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 766. Toeplitz Matrix
3 |
--------------------------------------------------------------------------------
/20. Valid Parentheses/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 20. Valid Parentheses
3 |
--------------------------------------------------------------------------------
/200. Number of Islands/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 200. Number of Islands
3 |
--------------------------------------------------------------------------------
/242. Valid Anagram/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 242. Valid Anagram
3 |
--------------------------------------------------------------------------------
/257. Binary Tree Paths/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 257. Binary Tree Paths
3 |
--------------------------------------------------------------------------------
/858. Mirror Reflection/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 858. Mirror Reflection
3 |
--------------------------------------------------------------------------------
/1020. Number of Enclaves/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1020. Number of Enclaves
3 |
--------------------------------------------------------------------------------
/1328. Break a Palindrome/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1328. Break a Palindrome
3 |
--------------------------------------------------------------------------------
/218. The Skyline Problem/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 218. The Skyline Problem
3 |
--------------------------------------------------------------------------------
/29. Divide Two Integers/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 29. Divide Two Integers
3 |
--------------------------------------------------------------------------------
/377. Combination Sum IV/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 377. Combination Sum IV
3 |
--------------------------------------------------------------------------------
/42. Trapping Rain Water/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 42. Trapping Rain Water
3 |
--------------------------------------------------------------------------------
/623. Add One Row to Tree/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 623. Add One Row to Tree
3 |
--------------------------------------------------------------------------------
/814. Binary Tree Pruning/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 814. Binary Tree Pruning
3 |
--------------------------------------------------------------------------------
/219. Contains Duplicate II/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 219. Contains Duplicate II
3 |
--------------------------------------------------------------------------------
/450. Delete Node in a BST/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 450. Delete Node in a BST
3 |
--------------------------------------------------------------------------------
/622. Design Circular Queue/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 622. Design Circular Queue
3 |
--------------------------------------------------------------------------------
/692. Top K Frequent Words/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 692. Top K Frequent Words
3 |
--------------------------------------------------------------------------------
/869. Reordered Power of 2/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 869. Reordered Power of 2
3 |
--------------------------------------------------------------------------------
/1531. String Compression II/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1531. String Compression II
3 |
--------------------------------------------------------------------------------
/234. Palindrome Linked List/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 234. Palindrome Linked List
3 |
--------------------------------------------------------------------------------
/35. Search Insert Position/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 35. Search Insert Position
3 |
--------------------------------------------------------------------------------
/1480. Running Sum of 1d Array/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1480. Running Sum of 1d Array
3 |
--------------------------------------------------------------------------------
/196. Delete Duplicate Emails/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 196. Delete Duplicate Emails
3 |
--------------------------------------------------------------------------------
/523. Continuous Subarray Sum/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 523. Continuous Subarray Sum
3 |
--------------------------------------------------------------------------------
/658. Find K Closest Elements/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 658. Find K Closest Elements
3 |
--------------------------------------------------------------------------------
/76. Minimum Window Substring/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 76. Minimum Window Substring
3 |
--------------------------------------------------------------------------------
/804. Unique Morse Code Words/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 804. Unique Morse Code Words
3 |
--------------------------------------------------------------------------------
/881. Boats to Save People/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 881. Boats to Save People
3 |
--------------------------------------------------------------------------------
/890. Find and Replace Pattern/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 890. Find and Replace Pattern
3 |
--------------------------------------------------------------------------------
/946. Validate Stack Sequences/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 946. Validate Stack Sequences
3 |
--------------------------------------------------------------------------------
/1220. Count Vowels Permutation/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1220. Count Vowels Permutation
3 |
--------------------------------------------------------------------------------
/1254. Number of Closed Islands/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1254. Number of Closed Islands
3 |
--------------------------------------------------------------------------------
/1679. Max Number of K-Sum Pairs/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1679. Max Number of K-Sum Pairs
3 |
--------------------------------------------------------------------------------
/2439. Minimize Maximum of Array/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 2439. Minimize Maximum of Array
3 |
--------------------------------------------------------------------------------
/349. Intersection of Two Arrays/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 349. Intersection of Two Arrays
3 |
--------------------------------------------------------------------------------
/508. Most Frequent Subtree Sum/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 508. Most Frequent Subtree Sum
3 |
--------------------------------------------------------------------------------
/53. Two Sum IV - Input is a BST/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 53. Two Sum IV - Input is a BST
3 |
--------------------------------------------------------------------------------
/710. Random Pick with Blacklist/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 710. Random Pick with Blacklist
3 |
--------------------------------------------------------------------------------
/823. Binary Trees With Factors/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 823. Binary Trees With Factors
3 |
--------------------------------------------------------------------------------
/936. Stamping The Sequence/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 936. Stamping The Sequence
3 |
--------------------------------------------------------------------------------
/976. Largest Perimeter Triangle/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 976. Largest Perimeter Triangle
3 |
--------------------------------------------------------------------------------
/981. Time Based Key-Value Store/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 981. Time Based Key-Value Store
3 |
--------------------------------------------------------------------------------
/1678. Goal Parser Interpretation/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1678. Goal Parser Interpretation
3 |
--------------------------------------------------------------------------------
/2405. Optimal Partition of String/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 2405. Optimal Partition of String
3 |
--------------------------------------------------------------------------------
/417. Pacific Atlantic Water Flow/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 417. Pacific Atlantic Water Flow
3 |
--------------------------------------------------------------------------------
/538. Convert BST to Greater Tree/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 538. Convert BST to Greater Tree
3 |
--------------------------------------------------------------------------------
/98. Validate Binary Search Tree/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 98. Validate Binary Search Tree
3 |
--------------------------------------------------------------------------------
/124. Binary Tree Maximum Path Sum/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 124. Binary Tree Maximum Path Sum
3 |
--------------------------------------------------------------------------------
/237. Delete Node in a Linked List/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 237. Delete Node in a Linked List
3 |
--------------------------------------------------------------------------------
/2390. Removing Stars From a String/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 2390. Removing Stars From a String
3 |
--------------------------------------------------------------------------------
/557. Reverse Words in a String III/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 557. Reverse Words in a String III
3 |
--------------------------------------------------------------------------------
/609. Find Duplicate File in System/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 609. Find Duplicate File in System
3 |
--------------------------------------------------------------------------------
/94. Binary Tree Inorder Traversal/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 94. Binary Tree Inorder Traversal
3 |
--------------------------------------------------------------------------------
/1329. Sort the Matrix Diagonally/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1329. Sort the Matrix Diagonally
3 |
--------------------------------------------------------------------------------
/1338. Reduce Array Size to The Half/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1338. Reduce Array Size to The Half
3 |
--------------------------------------------------------------------------------
/1383. Maximum Performance of a Team/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1383. Maximum Performance of a Team
3 |
--------------------------------------------------------------------------------
/1670. Design Front Middle Back Queue/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1670. Design Front Middle Back Queue
3 |
--------------------------------------------------------------------------------
/300. Longest Increasing Subsequence/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 300. Longest Increasing Subsequence
3 |
--------------------------------------------------------------------------------
/334. Increasing Triplet Subsequence/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 334. Increasing Triplet Subsequence
3 |
--------------------------------------------------------------------------------
/516. Longest Palindromic Subsequence/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 516. Longest Palindromic Subsequence
3 |
--------------------------------------------------------------------------------
/1448. Count Good Nodes in Binary Tree/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1448. Count Good Nodes in Binary Tree
3 |
--------------------------------------------------------------------------------
/1832. Check if the Sentence Is Pangram/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1832. Check if the Sentence Is Pangram
3 |
--------------------------------------------------------------------------------
/19. Remove Nth Node From End of List/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 19. Remove Nth Node From End of List
3 |
--------------------------------------------------------------------------------
/429. N-ary Tree Level Order Traversal/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 429. N-ary Tree Level Order Traversal
3 |
--------------------------------------------------------------------------------
/637. Average of Levels in Binary Tree/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 637. Average of Levels in Binary Tree
3 |
--------------------------------------------------------------------------------
/102. Binary Tree Level Order Traversal/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 102. Binary Tree Level Order Traversal
3 |
--------------------------------------------------------------------------------
/188. Best Time to Buy and Sell Stock IV/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 188. Best Time to Buy and Sell Stock IV
3 |
--------------------------------------------------------------------------------
/387. First Unique Character in a String/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 387. First Unique Character in a String
3 |
--------------------------------------------------------------------------------
/871. Minimum Number of Refueling Stops/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 871. Minimum Number of Refueling Stops
3 |
--------------------------------------------------------------------------------
/985. Sum of Even Numbers After Queries/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 985. Sum of Even Numbers After Queries
3 |
--------------------------------------------------------------------------------
/1578. Minimum Time to Make Rope Colorful/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1578. Minimum Time to Make Rope Colorful
3 |
--------------------------------------------------------------------------------
/1636. Sort Array by Increasing Frequency/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1636. Sort Array by Increasing Frequency
3 |
--------------------------------------------------------------------------------
/2136. Earliest Possible Day of Full Bloom/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 2136. Earliest Possible Day of Full Bloom
3 |
--------------------------------------------------------------------------------
/501. Find Mode in Binary Search Tree/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 501. Find Mode in Binary Search Tree
3 |
--------------------------------------------------------------------------------
/718. Maximum Length of Repeated Subarray/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 718. Maximum Length of Repeated Subarray
3 |
--------------------------------------------------------------------------------
/990. Satisfiability of Equality Equations/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 990. Satisfiability of Equality Equations
3 |
--------------------------------------------------------------------------------
/1155. Number of Dice Rolls With Target Sum/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1155. Number of Dice Rolls With Target Sum
3 |
--------------------------------------------------------------------------------
/1335. Minimum Difficulty of a Job Schedule/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1335. Minimum Difficulty of a Job Schedule
3 |
--------------------------------------------------------------------------------
/196. Delete Duplicate Emails/196. Delete Duplicate Emails.sql:
--------------------------------------------------------------------------------
1 | #Author: Devendra Uraon
2 |
3 | delete org from Person as org, Person as dup where org.email=dup.email and org.id>dup.id;
4 |
5 |
6 |
--------------------------------------------------------------------------------
/363. Max Sum of Rectangle No Larger Than K/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 363. Max Sum of Rectangle No Larger Than K
3 |
--------------------------------------------------------------------------------
/606. Construct String from Binary Tree/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 606. Construct String from Binary Tree
3 |
--------------------------------------------------------------------------------
/2007. Find Original Array From Doubled Array/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 2007. Find Original Array From Doubled Array
3 |
--------------------------------------------------------------------------------
/2300. Successful Pairs of Spells and Potions/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 2300. Successful Pairs of Spells and Potions
3 |
--------------------------------------------------------------------------------
/378. Kth Smallest Element in a Sorted Matrix/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 378. Kth Smallest Element in a Sorted Matrix
3 |
--------------------------------------------------------------------------------
/103. Binary Tree Zigzag Level Order Traversal/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 103. Binary Tree Zigzag Level Order Traversal
3 |
--------------------------------------------------------------------------------
/2095. Delete the Middle Node of a Linked List/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 2095. Delete the Middle Node of a Linked List
3 |
--------------------------------------------------------------------------------
/30. Substring with Concatenation of All Words/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 30. Substring with Concatenation of All Words
3 |
--------------------------------------------------------------------------------
/659. Split Array into Consecutive Subsequences/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 659. Split Array into Consecutive Subsequences
3 |
--------------------------------------------------------------------------------
/967. Numbers With Same Consecutive Differences/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 967. Numbers With Same Consecutive Differences
3 |
--------------------------------------------------------------------------------
/987. Vertical Order Traversal of a Binary Tree/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 987. Vertical Order Traversal of a Binary Tree
3 |
--------------------------------------------------------------------------------
/108. Convert Sorted Array to Binary Search Tree/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 108. Convert Sorted Array to Binary Search Tree
3 |
--------------------------------------------------------------------------------
/1457. Pseudo-Palindromic Paths in a Binary Tree/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1457. Pseudo-Palindromic Paths in a Binary Tree
3 |
--------------------------------------------------------------------------------
/1662. Check If Two String Arrays are Equivalent/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1662. Check If Two String Arrays are Equivalent
3 |
--------------------------------------------------------------------------------
/1996. The Number of Weak Characters in the Game/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1996. The Number of Weak Characters in the Game
3 |
--------------------------------------------------------------------------------
/2114. Maximum Number of Words Found in Sentences/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 2114. Maximum Number of Words Found in Sentences
3 |
--------------------------------------------------------------------------------
/1680. Concatenation of Consecutive Binary Numbers/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1680. Concatenation of Consecutive Binary Numbers
3 |
--------------------------------------------------------------------------------
/235. Lowest Common Ancestor of a Binary Search Tree/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 235. Lowest Common Ancestor of a Binary Search Tree
3 |
--------------------------------------------------------------------------------
/1293. Shortest Path in a Grid with Obstacles Elimination/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1293. Shortest Path in a Grid with Obstacles Elimination
3 |
--------------------------------------------------------------------------------
/1770. Maximum Score from Performing Multiplication Operations/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1770. Maximum Score from Performing Multiplication Operations
3 |
--------------------------------------------------------------------------------
/105. Construct Binary Tree from Preorder and Inorder Traversal/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 105. Construct Binary Tree from Preorder and Inorder Traversal
3 |
--------------------------------------------------------------------------------
/106. Construct Binary Tree from Inorder and Postorder Traversal/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 106. Construct Binary Tree from Inorder and Postorder Traversal
3 |
--------------------------------------------------------------------------------
/1239. Maximum Length of a Concatenated String with Unique Characters/README.md:
--------------------------------------------------------------------------------
1 | ## Question :
2 | 1239. Maximum Length of a Concatenated String with Unique Characters
3 |
--------------------------------------------------------------------------------
/237. Delete Node in a Linked List/237. Delete Node in a Linked List.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | void deleteNode(ListNode* node) {
5 | node -> val = node -> next -> val;
6 | node -> next = node -> next -> next;
7 | }
8 | };
9 |
--------------------------------------------------------------------------------
/509. Fibonacci Number/509. Fibonacci Number.cpp:
--------------------------------------------------------------------------------
1 | //Devendra Uraon
2 | class Solution {
3 | public:
4 | int fib(int N) {
5 | int f[N+2], i;
6 | f[0] = 0, f[1] = 1;
7 |
8 | for (i = 2; i <= N; i++){
9 | f[i] = f[i-1] + f[i-2];
10 | }
11 | return f[N];
12 | }
13 | };
14 |
--------------------------------------------------------------------------------
/136. Single Number/136. Single Number.cpp:
--------------------------------------------------------------------------------
1 | //Devendra Uraon
2 | class Solution {
3 | public:
4 | int singleNumber(vector& nums) {
5 | int sol = 0, T = nums.size(), i = 0;
6 | while(T--){
7 | sol = nums[i]^sol;
8 | ++i;
9 | }
10 | return sol;
11 | }
12 | };
13 |
--------------------------------------------------------------------------------
/458. Poor Pigs/458. Poor Pigs.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
5 | int t = (minutesToTest - 1) / minutesToDie + 1;
6 | if (buckets == 1) return 0;
7 | return log(buckets - 1) / log(t + 1) + 1;
8 | }
9 | };
10 |
--------------------------------------------------------------------------------
/231. Power of Two/231. Power of Two.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool isPowerOfTwo(int n) {
5 | if(n == 0)
6 | return 0;
7 | while(n != 1){
8 | if(n % 2 != 0)
9 | return 0;
10 | n = n / 2;
11 | }
12 | return 1;
13 | }
14 | };
15 |
--------------------------------------------------------------------------------
/342. Power of Four/342. Power of Four.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool isPowerOfFour(int n) {
5 | if(n == 0)
6 | return 0;
7 | while(n != 1){
8 | if(n % 4 != 0)
9 | return 0;
10 | n = n / 4;
11 | }
12 | return 1;
13 | }
14 | };
15 |
--------------------------------------------------------------------------------
/387. First Unique Character in a String/387. First Unique Character in a String.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int firstUniqChar(string s) {
5 | vector v(26,0);
6 | for(char c : s) v[c - 'a']++;
7 | for(int i = 0; i < s.size(); i++) if(v[s[i] - 'a'] == 1) return i;
8 | return -1;
9 | }
10 | };
11 |
--------------------------------------------------------------------------------
/112. Path Sum/112. Path Sum.cpp:
--------------------------------------------------------------------------------
1 | //Devendra Uraon
2 | class Solution {
3 | public:
4 | bool hasPathSum(TreeNode* root, int sum) {
5 | if(root == NULL) return false;
6 | sum -= root->val;
7 | return sum == 0 && root->left == NULL && root->right == NULL ? true : hasPathSum(root->left, sum) | hasPathSum(root->right, sum);
8 | }
9 | };
10 |
--------------------------------------------------------------------------------
/1832. Check if the Sentence Is Pangram/1832. Check if the Sentence Is Pangram.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool checkIfPangram(string sentence) {
5 | unordered_map mp;
6 | for( int i = 0; i < sentence.size(); i++) mp[sentence[i]]++;
7 | if(mp.size() == 26) return true;
8 | return false;
9 | }
10 | };
11 |
--------------------------------------------------------------------------------
/326. Power of Three/326. Power of Three.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool isPowerOfThree(int n) {
5 | if(n == 0)
6 | return 0;
7 | while(n != 1){
8 | if(n % 3 != 0)
9 | return 0;
10 | n = n / 3;
11 | }
12 | return 1;
13 | }
14 | };
15 |
--------------------------------------------------------------------------------
/100. Same Tree/100. Same Tree.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool isSameTree(TreeNode* p, TreeNode* q) {
5 | if(!p && !q) return true;
6 | if(!p || !q) return false;
7 | if(p -> val != q -> val) return false;
8 | return isSameTree(p -> left, q -> left) && isSameTree(p -> right, q -> right);
9 | }
10 | };
11 |
--------------------------------------------------------------------------------
/1662. Check If Two String Arrays are Equivalent/1662. Check If Two String Arrays are Equivalent.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool arrayStringsAreEqual(vector& word1, vector& word2) {
5 | string s1, s2;
6 | for(auto &i: word1) s1+=i;
7 | for(auto &i: word2) s2+=i;
8 | return s1 == s2;
9 | }
10 | };
11 |
--------------------------------------------------------------------------------
/1480. Running Sum of 1d Array/1480. Running Sum of 1d Array.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | vector runningSum(vector& nums) {
5 | vector solve;
6 | int sum = 0;
7 | for(int i = 0; i < nums.size(); i++){
8 | sum += nums[i];
9 | solve.push_back(sum);
10 | }
11 | return solve;
12 | }
13 | };
14 |
--------------------------------------------------------------------------------
/814. Binary Tree Pruning/814. Binary Tree Pruning.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | TreeNode* pruneTree(TreeNode* root) {
5 | if(!root) return NULL;
6 | root->left = pruneTree(root -> left);
7 | root->right = pruneTree(root -> right);
8 | if(root->val == 0 && !root -> left && !root -> right) return NULL;
9 | return root;
10 | }
11 | };
12 |
--------------------------------------------------------------------------------
/35. Search Insert Position/35. Search Insert Position.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int searchInsert(vector& nums, int target) {
5 | int low = 0, high = nums.size()-1;
6 | while (low <= high) {
7 | int mid = low + (high-low)/2;
8 | if ((nums[mid] < target) ? low = mid+1 : high = mid-1);
9 | }
10 | return low;
11 | }
12 | };
13 |
--------------------------------------------------------------------------------
/946. Validate Stack Sequences/946. Validate Stack Sequences.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool validateStackSequences(vector &push, vector &pop) {
5 | stack s;
6 | for (int i = 0, j = 0; i < push.size(); ++i) {
7 | s.push(push[i]);
8 | while (!s.empty() && s.top() == pop[j]) s.pop(), ++j;
9 | }
10 | return s.empty();
11 | }
12 | };
13 |
14 |
15 |
--------------------------------------------------------------------------------
/13. Roman to Integer/13. Roman to Integer.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int romanToInt(string s) {
5 | unordered_map mp = {{'M', 1000}, {'D', 500}, {'C', 100}, {'L', 50}, {'X', 10}, {'V', 5}, {'I', 1}};
6 | int sum = mp[s.back()];
7 | for(int i = 0; i < s.size() - 1; i++) {
8 | if(mp[s[i]] < mp[s[i + 1]]) sum-= mp[s[i]];
9 | else sum += mp[s[i]];
10 | }
11 | return sum;
12 | }
13 | };
14 |
--------------------------------------------------------------------------------
/1680. Concatenation of Consecutive Binary Numbers/1680. Concatenation of Consecutive Binary Numbers.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int concatenatedBinary(int n) {
5 | long long int val = 0;
6 | int i = 1;
7 | while(i <= n)
8 | {
9 | val = ((val << (1 + int(log2(i)))) % 1000000007 +i) % 1000000007;
10 | i++ ;
11 | }
12 | return val;
13 | }
14 | };
15 |
--------------------------------------------------------------------------------
/1254. Number of Closed Islands/1254. Number of Closed Islands.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int minimizeArrayValue(vector& nums) {
5 | int n = nums.size();
6 | long long ans = nums[0];
7 | long long sum = nums[0];
8 | for(int i = 1; i < n; i++){
9 | sum += nums[i];
10 | ans = max(ans, (sum + i) / (i + 1));
11 | }
12 | return ans;
13 | }
14 | };
15 |
--------------------------------------------------------------------------------
/2439. Minimize Maximum of Array/2439. Minimize Maximum of Array.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int minimizeArrayValue(vector& nums) {
5 | int n = nums.size();
6 | long long ans = nums[0];
7 | long long sum = nums[0];
8 | for(int i = 1; i < n; i++){
9 | sum += nums[i];
10 | ans = max(ans, (sum + i) / (i + 1));
11 | }
12 | return ans;
13 | }
14 | };
15 |
--------------------------------------------------------------------------------
/976. Largest Perimeter Triangle/976. Largest Perimeter Triangle.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int largestPerimeter(vector& nums) {
5 | sort(nums.begin(), nums.end());
6 | int mx = 0;
7 | for(int i = nums.size()-1; i >= 2; i--){
8 | if(nums[i-2]+nums[i-1] > nums[i]){
9 | return nums[i] + nums[i-1] + nums[i-2];
10 | }
11 | }
12 | return 0;
13 | }
14 | };
15 |
--------------------------------------------------------------------------------
/704. Binary Search/704. Binary Search.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int search(vector& nums, int target) {
5 | int s = 0;
6 | int e = nums.size() - 1;
7 | while(s <= e){
8 | int mid = s + (e - s) / 2;
9 | if(nums[mid] == target) return mid;
10 | else if(nums[mid] > target) e = mid - 1;
11 | else s = mid + 1;
12 | }
13 | return -1;
14 | }
15 | };
16 |
--------------------------------------------------------------------------------
/94. Binary Tree Inorder Traversal/94. Binary Tree Inorder Traversal.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | vectorv;
5 | void inorder(TreeNode* root){
6 | if(root == NULL)
7 | return;
8 |
9 | inorder(root -> left);
10 | v.push_back(root -> val);
11 | inorder(root -> right);
12 | }
13 | vector inorderTraversal(TreeNode* root) {
14 | inorder(root);
15 | return v;
16 | }
17 | };
18 |
--------------------------------------------------------------------------------
/2405. Optimal Partition of String/2405. Optimal Partition of String.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int partitionString(string s) {
5 | vector mp(26, 0);
6 | int ans = 1;
7 | for(char c: s)
8 | {
9 | if(mp[c - 'a'] != 0)
10 | {
11 | mp = vector(26, 0);
12 | ans++;
13 | }
14 | mp[c - 'a']++;
15 | }
16 | return ans;
17 | }
18 | };
19 |
--------------------------------------------------------------------------------
/1328. Break a Palindrome/1328. Break a Palindrome.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | string breakPalindrome(string palindrome) {
5 | int n = palindrome.size();
6 | if(n <= 1) return "";
7 | for(int i = 0; i < n/2; i++){
8 | if(palindrome[i] != 'a'){
9 | palindrome[i] = 'a';
10 | return palindrome;
11 | }
12 | }
13 | palindrome[n-1] = 'b';
14 | return palindrome;
15 | }
16 | };
17 |
--------------------------------------------------------------------------------
/378. Kth Smallest Element in a Sorted Matrix/378. Kth Smallest Element in a Sorted Matrix.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int kthSmallest(vector>& matrix, int k)
5 | {
6 | priority_queue pq;
7 | for(int i=0;ik) pq.pop();
11 | }
12 | }
13 | return pq.top();
14 | }
15 | };
16 |
--------------------------------------------------------------------------------
/124. Binary Tree Maximum Path Sum/124. Binary Tree Maximum Path Sum.cpp:
--------------------------------------------------------------------------------
1 | //Devendra Uraon
2 | class Solution {
3 | public:
4 | int helper(TreeNode* x, int &line) {
5 | if (x == NULL) return INT_MIN;
6 | int ll = 0, rl = 0, lm = helper(x->left, ll), rm = helper(x->right, rl);
7 | line = max(0, max(ll, rl) + x->val);
8 | return max(ll + rl + x->val, max(lm, rm));
9 | }
10 | int maxPathSum(TreeNode* root) {
11 | int line = 0;
12 | return helper(root, line);
13 | }
14 | };
15 |
--------------------------------------------------------------------------------
/219. Contains Duplicate II/219. Contains Duplicate II.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool containsNearbyDuplicate(vector& nums, int k) {
5 | size_t size = nums.size();
6 | int i;
7 | unordered_map m;
8 | for (i = 0; i < size; ++i) {
9 | if (m.find(nums[i]) == m.end()) m[nums[i]] = i;
10 | else if (i-m[nums[i]] <= k) return true;
11 | else m[nums[i]] = i;
12 | }
13 | return false;
14 | }
15 | };
16 |
--------------------------------------------------------------------------------
/235. Lowest Common Ancestor of a Binary Search Tree/235. Lowest Common Ancestor of a Binary Search Tree.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
5 | if( root->val > p->val && root->val > q->val)
6 | return lowestCommonAncestor( root->left, p, q);
7 | if( root->val < p->val && root->val < q->val)
8 | return lowestCommonAncestor( root->right, p, q);
9 | return root;
10 | }
11 | };
12 |
--------------------------------------------------------------------------------
/858. Mirror Reflection/858. Mirror Reflection.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int mirrorReflection(int p, int q) {
5 | while((p%2==0) && (q%2==0)){ //executing till getting odd either p or q
6 | p/=2; q/=2;
7 | }
8 | if((p%2) == 0 && (q%2)!=0) return 2; //p = even, q = odd
9 | if((p%2) != 0 && (q%2)!=0) return 1; //p = odd, q = odd
10 | return 0; //p = odd, q = even
11 | }
12 | };
13 |
--------------------------------------------------------------------------------
/48. Rotate Image/48. Rotate Image.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | void transpose(vector> &mat){
5 | int m = mat.size();
6 |
7 | for(int i = 0; i < m; i++){
8 | for(int j = i; j < m; j++){
9 | swap(mat[i][j], mat[j][i]);
10 | }
11 | }
12 | }
13 | void rotate(vector>& matrix) {
14 | transpose(matrix);
15 |
16 | for(auto &i:matrix) reverse(i.begin(), i.end());
17 | }
18 | };
19 |
--------------------------------------------------------------------------------
/2095. Delete the Middle Node of a Linked List/2095. Delete the Middle Node of a Linked List.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | ListNode* deleteMiddle(ListNode* head) {
5 | if(head -> next == NULL) return head -> next;
6 | ListNode* slow = head, *fast = head, *prev = NULL;
7 | while(fast && fast -> next) {
8 | prev = slow;
9 | slow = slow -> next;
10 | fast = fast -> next->next;
11 | }
12 | prev -> next = slow -> next;
13 | return head;
14 | }
15 | };
16 |
--------------------------------------------------------------------------------
/869. Reordered Power of 2/869. Reordered Power of 2.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | unordered_setmp;
5 | Solution(){
6 |
7 | int n=1;
8 | while(n<=1000000000){
9 | string s=to_string(n);
10 | sort(s.begin(),s.end());
11 | mp.insert(s);
12 | n<<=1;
13 | }
14 | }
15 | bool reorderedPowerOf2(int n) {
16 | string v=to_string(n);
17 | sort(v.begin(),v.end());
18 | return mp.count(v);
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/12. Integer to Roman/12. Integer to Roman.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | string intToRoman(int num) {
5 | int n[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
6 | string roman[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
7 |
8 | int i = 0;
9 | string ans;
10 | while (num != 0){
11 | while (n[i] > num) ++i;
12 | num = num - n[i];
13 | ans += roman[i];
14 | }
15 | return ans;
16 | }
17 | };
18 |
--------------------------------------------------------------------------------
/2114. Maximum Number of Words Found in Sentences/2114. Maximum Number of Words Found in Sentences.cpp:
--------------------------------------------------------------------------------
1 | //Devendra Uraon
2 | class Solution {
3 | public:
4 | int mostWordsFound(vector& sentences) {
5 |
6 | int maax=INT_MIN;
7 |
8 | for(int i=0;i& nums) {
5 | if(nums.size() < 3) return false;
6 | int first = INT_MAX, second = INT_MAX;
7 | for(int i = 0; i < nums.size(); i++){
8 | if(nums[i] > second) return true;
9 | else if(nums[i]>first && nums[i]val >= currentMax || currentMax == INT_MIN) sum++;
7 | doRec(root->left, max(currentMax, root->val));
8 | doRec(root->right, max(currentMax, root->val));
9 | }
10 | }
11 | public:
12 | int goodNodes(TreeNode* root) {
13 | doRec(root, INT_MIN);
14 | return sum;
15 | }
16 | };
17 |
--------------------------------------------------------------------------------
/658. Find K Closest Elements/658. Find K Closest Elements.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | vector findClosestElements(vector& arr, int k, int x) {
5 | priority_queue, vector>> pq;
6 | for(auto n: arr){
7 | pq.push({abs(n - x), n});
8 | if(pq.size() > k) pq.pop();
9 | }
10 | vector ans;
11 | while(!pq.empty()) ans.push_back(pq.top().second), pq.pop();
12 | sort(ans.begin(), ans.end());
13 | return ans;
14 | }
15 | };
16 |
--------------------------------------------------------------------------------
/300. Longest Increasing Subsequence/300. Longest Increasing Subsequence.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int lengthOfLIS(vector& nums) {
5 | set s;
6 | int n = nums.size();
7 | for(int i = 0; i < n; i++) {
8 | auto it = s.lower_bound(nums[i]);
9 | if(it == s.end()) {
10 | s.insert(nums[i]);
11 | continue;
12 | }
13 | s.erase(it);
14 | s.insert(nums[i]);
15 | }
16 | return (int)s.size();
17 | }
18 | };
19 |
--------------------------------------------------------------------------------
/49. Group Anagrams/49. Group Anagrams.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | vector> groupAnagrams(vector& strs) {
5 |
6 | unordered_map> m;
7 | for(auto it:strs){
8 | string temp = it;
9 | sort(temp.begin(), temp.end());
10 | m[temp].push_back(it);
11 | }
12 |
13 | vector> ans;
14 | for(auto [temp,vec]:m)
15 | ans.push_back(vec);
16 |
17 | return ans;
18 | }
19 | };
20 |
--------------------------------------------------------------------------------
/766. Toeplitz Matrix/766. Toeplitz Matrix.cpp:
--------------------------------------------------------------------------------
1 | //Devendra Uraon
2 | class Solution {
3 | public:
4 | bool isToeplitzMatrix(const vector>& m) {
5 | if (m.empty()) {
6 | return true;
7 | }
8 | const auto n = m[0].size() - 1;
9 | for (auto i = 1u; i < m.size(); ++i) {
10 | const auto b1 = m[i - 1].begin();
11 | const auto b2 = m[i].begin();
12 | if (!equal(b1, b1 + n, b2 + 1)) {
13 | return false;
14 | }
15 | }
16 | return true;
17 | }
18 | };
19 |
--------------------------------------------------------------------------------
/729. My Calendar I/729. My Calendar I.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class MyCalendar {
3 | vector> vec;
4 | public:
5 | MyCalendar() {
6 |
7 | }
8 |
9 | bool book(int start, int end) {
10 | for (auto date: vec)
11 | if ((start >= date.first && start < date.second) or
12 | (end > date.first && end < date.second) or
13 | (start <= date.first && end > date.first))
14 | return false;
15 |
16 | vec.push_back({start, end});
17 | return true;
18 | }
19 | };
20 |
--------------------------------------------------------------------------------
/1679. Max Number of K-Sum Pairs/1679. Max Number of K-Sum Pairs.cpp:
--------------------------------------------------------------------------------
1 | //Devendra Uraon
2 | class Solution {
3 | public:
4 | int maxOperations(vector& nums, int k) {
5 | int ans=0;
6 | unordered_map mp;
7 | mp[nums[0]]++;
8 | for(int i=1;i0){
10 | mp[k-nums[i]]--; // Decreasing the count of other number in the map
11 | ans++;
12 | }
13 | else mp[nums[i]]++;
14 | }
15 | return ans;
16 | }
17 | };
18 |
--------------------------------------------------------------------------------
/242. Valid Anagram/242. Valid Anagram.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool isAnagram(string s, string t) {
5 | int alphabet[26]={0};
6 | for(int i = 0; i < s.size(); i++){
7 | alphabet[s[i]-'a']++;
8 | }
9 | int alphabet1[26]={0};
10 | for(int i = 0; i < t.size(); i++){
11 | alphabet1[t[i]-'a']++;
12 | }
13 | bool flag = 1;
14 | for(int i = 0; i<26; i++){
15 | if(alphabet[i] != alphabet1[i]){
16 | flag = 0;
17 | break;
18 | }
19 | }
20 | return flag;
21 | }
22 | };
23 |
--------------------------------------------------------------------------------
/645. Set Mismatch/645. Set Mismatch.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | vector findErrorNums(vector& nums) {
5 | unordered_map mp;
6 | vector ans;
7 | for(int i=1; i<=nums.size(); i++) mp[i] = 1;
8 | for(auto n : nums){
9 | mp[n]--;
10 | if(mp[n] < 0) ans.push_back(n);
11 | }
12 | for(auto m : mp){
13 | if(m.second == 1){
14 | ans.push_back(m.first);
15 | break;
16 | }
17 | }
18 | return ans;
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/538. Convert BST to Greater Tree/538. Convert BST to Greater Tree.cpp:
--------------------------------------------------------------------------------
1 | //Devendra Uraon
2 | class Solution {
3 | private:
4 | vector num;
5 | void treeToVector(TreeNode *root) {
6 | if (!root) return;
7 | treeToVector(root->left);
8 | num.push_back(root);
9 | treeToVector(root->right);
10 | }
11 | public:
12 | TreeNode* convertBST(TreeNode* root) {
13 | treeToVector(root);
14 | if (num.size() <= 1) return root;
15 | for (int i = num.size()-2; i >= 0; i--) { num[i]->val += num[i+1]->val; }
16 | return root;
17 | }
18 | };
19 |
--------------------------------------------------------------------------------
/62. Unique Paths/62. Unique Paths.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int uniquePaths(int m, int n) {
5 | double num = 1, div = 1;
6 | int max, min;
7 |
8 | if (m > n){
9 | max = m - 1;
10 | min = n - 1;
11 | }
12 | else{
13 | max = n - 1;
14 | min = m - 1;
15 | }
16 |
17 | for(int i = max + min; i > max; i--)
18 | num *= i;
19 | for (int i = 1; i <= min; i++)
20 | div *= i;
21 |
22 | return num / div;
23 | }
24 | };
25 |
--------------------------------------------------------------------------------
/349. Intersection of Two Arrays/349. Intersection of Two Arrays.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | vector intersection(vector& a, vector& b) {
5 |
6 | unordered_set s;
7 | for(int i=0; i res;
11 |
12 | for(int j=0; j &N)
6 | {
7 | int mid=(e+b)/2;
8 |
9 | TreeNode *R=new TreeNode(N[mid]);
10 |
11 | if(mid>b) R->left= Make(b,mid-1,N);
12 | if(midright=Make(mid+1,e,N);
13 |
14 | return(R);
15 | }
16 |
17 |
18 | TreeNode* sortedArrayToBST(vector& N) {
19 |
20 | int n=N.size();
21 | return(Make(0,n-1,N));
22 | }
23 | };
24 |
--------------------------------------------------------------------------------
/19. Remove Nth Node From End of List/19. Remove Nth Node From End of List.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | ListNode* removeNthFromEnd(ListNode* head, int n) {
5 | ListNode* ptr1 = head;
6 | while(n-- && ptr1)
7 | ptr1 = ptr1 -> next;
8 | ListNode* ptr2 = head;
9 | if(ptr1 != NULL){
10 | while(ptr1 -> next){
11 | ptr1 = ptr1 -> next;
12 | ptr2 = ptr2 -> next;
13 | }
14 | ptr2 -> next = ptr2 -> next -> next;
15 | }
16 | else head = head -> next;
17 | return head;
18 | }
19 | };
20 |
--------------------------------------------------------------------------------
/257. Binary Tree Paths/257. Binary Tree Paths.cpp:
--------------------------------------------------------------------------------
1 | //Devendra Uraon
2 | class Solution {
3 | public:
4 | vector ans;
5 | void fun(TreeNode* root,string s)
6 | {
7 | if(!root->left && !root->right)
8 | ans.push_back(s);
9 | if(root->left)
10 | fun(root->left,s+"->"+to_string(root->left->val));
11 | if(root->right)
12 | fun(root->right,s+"->"+to_string(root->right->val));
13 | }
14 |
15 | vector binaryTreePaths(TreeNode* root) {
16 | string s="";
17 | s+=to_string(root->val);
18 | fun(root,s);
19 | return ans;
20 | }
21 | };
22 |
--------------------------------------------------------------------------------
/377. Combination Sum IV/377. Combination Sum IV.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int solve(vector &nums, int target,vector &dp){
5 | if(target < 0) return 0;
6 | if(target == 0) return 1;
7 | if(dp[target] != -1) return dp[target];
8 | int ans = 0;
9 | for(int i=0; i& nums, int target) {
15 | vector dp(target+1, -1);
16 | return solve(nums, target, dp);
17 | }
18 | };
19 |
--------------------------------------------------------------------------------
/516. Longest Palindromic Subsequence/516. Longest Palindromic Subsequence.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int longestPalindromeSubseq(string s) {
5 | string s2 = s;
6 | reverse(s2.begin(), s2.end());
7 | vector pre(s.size()+1, 0), cur(s.size()+1, 0);
8 | for(int i = 1; i <= s.size(); i++){
9 | for(int j = 1; j <= s.size(); j++){
10 | if(s[i-1] == s2[j-1]) cur[j] = 1 + pre[j-1];
11 | else cur[j] = max(pre[j], cur[j-1]);
12 | }
13 | pre = cur;
14 | }
15 | return pre[s.size()];
16 | }
17 | };
18 |
19 |
20 |
--------------------------------------------------------------------------------
/1678. Goal Parser Interpretation/1678. Goal Parser Interpretation.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | string interpret(string command) {
5 | ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
6 | string ans;
7 | for( int i = 0 ; i <= command.size()-1 ; i++){
8 | if(command[i] == 'G'){
9 | ans += 'G';
10 | }
11 | if(command[i] == '('){
12 | if(command[i+1] == ')')
13 | ans += 'o';
14 | else
15 | ans += "al";
16 | }
17 | }
18 | return ans;
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/606. Construct String from Binary Tree/606. Construct String from Binary Tree.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | private:
4 | void bi(TreeNode*root, string &s){
5 | if(root==NULL)
6 | return;
7 | s += "(";
8 | s += to_string(root->val);
9 | if(root -> left) bi(root -> left, s);
10 | else
11 | if(root -> right)
12 | s += "()";
13 | bi(root->right, s);
14 | s += ")";
15 | return;
16 | }
17 | public:
18 | string tree2str(TreeNode* root) {
19 | string s;
20 | bi(root, s);
21 | return s.substr(1, s.size()-2);
22 | }
23 | };
24 |
--------------------------------------------------------------------------------
/523. Continuous Subarray Sum/523. Continuous Subarray Sum.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool checkSubarraySum(vector& nums, int k) {
5 | int n = nums.size();
6 | if(n == 1) return false;
7 | unordered_map m;
8 | int sum = nums[0];
9 | m[sum%k] = 0;
10 | for(int i = 1; i < n; i++){
11 | sum += nums[i];
12 | if(sum%k == 0) return true;
13 | if(m.find(sum%k) != m.end() && i - m[sum%k] >= 2) return true;
14 | if( (nums[i-1] + nums[i]) %k == 0) return true;
15 | m[sum%k] = i;
16 | }
17 | return false;
18 | }
19 | };
20 |
--------------------------------------------------------------------------------
/53. Two Sum IV - Input is a BST/53. Two Sum IV - Input is a BST.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | vector v;
5 | void inorder(TreeNode* root){
6 | if(!root) return ;
7 | inorder(root -> left);
8 | v.push_back(root -> val);
9 | inorder(root -> right);
10 | }
11 | bool findTarget(TreeNode* root, int k){
12 | if(!root) return false;
13 | inorder(root);
14 | int l = 0, r = v.size()-1;
15 | while(l < r){
16 | if(v[l]+v[r] == k) return true;
17 | else if(v[l]+v[r]>& stations) {
5 | vector dp(stations.size() + 1, startFuel);
6 | for(int i = 0; i < stations.size(); i++) {
7 | for(int t = i; t >= 0; t--) {
8 | if(dp[t] < stations[i][0]) break;
9 | dp[t + 1] = max(dp[t + 1], stations[i][1] + dp[t]);
10 | }
11 | }
12 | for(int i = 0; i <= stations.size(); i++){
13 | if(dp[i]>=target)return i;
14 | }
15 | return -1;
16 | }
17 | };
18 |
--------------------------------------------------------------------------------
/985. Sum of Even Numbers After Queries/985. Sum of Even Numbers After Queries.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | vector sumEvenAfterQueries(vector& n, vector>& q) {
5 | int sum = 0, val, index;
6 | vector vec;
7 | for(int i = 0; i < n.size(); i++) if(n[i]%2 == 0) sum += n[i];
8 | for(int i = 0; i < q.size(); i++){
9 | val = q[i][0];
10 | index = q[i][1];
11 | if(n[index]%2 == 0) sum -= n[index];
12 | n[index] += val;
13 | if(n[index]%2 == 0) sum += n[index];
14 | vec.push_back(sum);
15 | }
16 | return vec;
17 | }
18 | };
19 |
--------------------------------------------------------------------------------
/796. Rotate String/796. Rotate String.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool rotateString(string s, string goal) {
5 | queue q;
6 | int n=s.size();
7 |
8 | for(char c:goal)
9 | q.push(c);
10 |
11 | while(n--){
12 | if(q.front() == s[0]){
13 | queue tq = q;
14 | string str;
15 |
16 | while(tq.size()){
17 | str += tq.front();
18 | tq.pop();
19 | }
20 | if(str == s) return true;
21 | }
22 | char y=q.front();
23 | q.push(y);
24 | q.pop();
25 | }
26 | return false;
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/393. UTF-8 Validation/393. UTF-8 Validation.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool validUtf8(vector& data) {
5 | int m[6] = {128, 192, 224, 240, 248, 10000000};
6 | int nbits,remaningbits = 0;
7 | for(auto d: data){
8 | nbits = 0;
9 | while(d >= m[nbits]) nbits++;
10 | if (nbits >= 5) return false;
11 | if (remaningbits>0){
12 | if (nbits!=1) return false;
13 | remaningbits--;
14 | }
15 | else if (nbits >= 2) remaningbits = nbits-1;
16 | else if (nbits == 1) return false;
17 | }
18 | return remaningbits == 0;
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/804. Unique Morse Code Words/804. Unique Morse Code Words.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int uniqueMorseRepresentations(vector& words) {
5 | vector a = {".-","-...","-.-.","-..",".","..-.","--.","....",
6 | "..",".---","-.-",".-..","--","-.","---",".--.",
7 | "--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
8 |
9 | unordered_map um;
10 |
11 | for (int i=0; i< words.size(); i++) {
12 | string st;
13 | for (int j=0; j> ans;
4 | vector path;
5 | int sum = 0, target;
6 |
7 | void dfs(TreeNode* x) {
8 | if (!x) return;
9 | sum += x->val;
10 | path.push_back(x -> val);
11 | if (sum == target && !x -> left && !x -> right)
12 | ans.push_back(path);
13 | dfs(x -> left);
14 | dfs(x -> right);
15 | sum -= x -> val;
16 | path.pop_back();
17 | }
18 |
19 | public:
20 | vector> pathSum(TreeNode* root, int targetSum) {
21 | target = targetSum;
22 | dfs(root);
23 | return ans;
24 | }
25 | };
26 |
--------------------------------------------------------------------------------
/29. Divide Two Integers/29. Divide Two Integers.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int divide(int dividend, int divisor) {
5 | //bitwise
6 | long long n = dividend;
7 | long long m = divisor;
8 | int res = n<0 ^ m<0 ? -1 : 1;
9 | n = abs(n);
10 | m = abs(m);
11 | long long q=0, t=0;
12 | for(long long i = 31; i>=0; i--){
13 | if(t + (m<= INT_MAX) return INT_MAX;
21 | return q;
22 | }
23 | };
24 |
--------------------------------------------------------------------------------
/1996. The Number of Weak Characters in the Game/1996. The Number of Weak Characters in the Game.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | static bool cmp(vector& v1,vector& v2){
5 | return v1[0] == v2[0] ? v1[1]>v2[1] : v1[0]>& nums){
8 | int n = nums.size(), count = 0;
9 | sort(nums.begin(), nums.end(), cmp);
10 | stack s;
11 | for(int i = 0; i < n; i++){
12 | while(s.size() && s.top() successfulPairs(vector& v1, vector& v2, long long success) {
5 | sort(v2.begin(), v2.end());
6 | int n = v1.size(), m = v2.size();
7 | vector ans;
8 | for (int i = 0; i < n; i++) {
9 | long long req = (success + v1[i] - 1) / v1[i];
10 | if (req > v2[m - 1]) {
11 | ans.push_back(0);
12 | continue;
13 | }
14 | auto it = lower_bound(v2.begin(), v2.end(), req);
15 | ans.push_back(v2.end() - it);
16 | }
17 | return ans;
18 | }
19 | };
20 |
--------------------------------------------------------------------------------
/71. Simplify Path/71. Simplify Path.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | string simplifyPath(string path) {
5 | string token = "";
6 |
7 | stringstream ss(path);
8 |
9 | stack stk;
10 |
11 | while(getline(ss, token, '/')){
12 | if(token == "" || token == ".") continue;
13 |
14 | if(token != "..") stk.push(token);
15 | else if(!stk.empty()) stk.pop();
16 | }
17 |
18 | if(stk.empty())
19 | return "/";
20 |
21 | string res = "";
22 |
23 | while(!stk.empty()){
24 | res = "/" + stk.top() + res;
25 | stk.pop();
26 | }
27 | return res;
28 | }
29 | };
30 |
--------------------------------------------------------------------------------
/38. Count and Say/38. Count and Say.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | string countAndSay(int n) {
5 | if(n == 1)
6 | return "1";
7 |
8 | string s = "1";
9 | for(int i=2; i<=n; i++){
10 | string t = "";
11 | s = s + '/';
12 | int count = 1;
13 | for(int j=1; j averageOfLevels(TreeNode* root) {
5 | vector ans;
6 | queue q;
7 | q.push(root);
8 | while(!q.empty()) {
9 | long temp = 0;
10 | int n = q.size();
11 | for(int i = 0; i < n; i++) {
12 | TreeNode* t = q.front();
13 | q.pop();
14 | if(t->left) q.push(t->left);
15 | if(t->right) q.push(t->right);
16 | temp += t->val;
17 | }
18 | ans.push_back((double)temp/n);
19 | }
20 | return ans;
21 | }
22 | };
23 |
--------------------------------------------------------------------------------
/383. Ransom Note/326. Power of Three.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool canConstruct(string ransomNote, string magazine) {
5 | bool a = 0;
6 | int alphabet[26]={0};
7 | int alphabet1[26]={0};
8 | for(int i = 0; i < ransomNote.size(); i++){
9 | alphabet[ransomNote[i]-'a']++;
10 | }
11 | for(int i = 0; i < magazine.size(); i++){
12 | alphabet1[magazine[i]-'a']++;
13 | }
14 | for(int i = 0; i < ransomNote.size(); i++){
15 | if(alphabet[ransomNote[i]-'a'] <= alphabet1[ransomNote[i]-'a']){
16 | a = 1;
17 | }
18 | else{
19 | a = 0;
20 | break;
21 | }
22 | }
23 | return a;
24 | }
25 | };
26 |
--------------------------------------------------------------------------------
/732. My Calendar III/732. My Calendar III.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class MyCalendarThree {
3 | public:
4 | vector s;
5 | vector e;
6 | int maxi = 0;
7 |
8 | void check(){
9 | sort(s.begin(),s.end());
10 | sort(e.begin(),e.end());
11 | int i = 0, j = 0, ans = 0;
12 | while(i& tokens, int power) {
5 | int c = 0;
6 | sort(tokens.begin(),tokens.end());
7 | int l = 0, r = tokens.size()-1;
8 | int ans = 0;
9 | while(l <= r){
10 | if(power >= tokens[l]){
11 | c++;
12 | ans = max(ans,c);
13 | power -= tokens[l];
14 | l++;
15 | }
16 | else if(power < tokens[l] && c>=1){
17 | power += tokens[r];
18 | c--; r--;
19 | }
20 | else if(c==0)
21 | break;
22 | }
23 | return ans;
24 | }
25 | };
26 |
--------------------------------------------------------------------------------
/659. Split Array into Consecutive Subsequences/659. Split Array into Consecutive Subsequences.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | bool isPossible(vector& nums){
5 | unordered_map left,end;
6 | for(int i:nums){
7 | left[i]++;
8 | }
9 | for(int i:nums){
10 | if(left[i]!=0){
11 | left[i]--;
12 | if(end[i-1]>0){
13 | end[i-1]--;
14 | end[i]++;
15 | }
16 | else if(left[i+1]>0 && left[i+2]>0){
17 | left[i+1]--;
18 | left[i+2]--;
19 | end[i+2]++;
20 | }
21 | else return false;
22 | }
23 | }
24 | return true;
25 | }
26 | };
27 |
--------------------------------------------------------------------------------
/823. Binary Trees With Factors/823. Binary Trees With Factors.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int numFactoredBinaryTrees(vector& A) {
5 | sort(A.begin(), A.end());
6 | const long Mod = 1e9+7;
7 | unordered_map dp;
8 | for(int i = 0; i < A.size(); i++){
9 | dp[A[i]] = 1;
10 | for(int j = 0; j < i; j++){ // A[i] = A[j] * A[i]/A[j]
11 | if(A[i] % A[j] ==0 && dp.count(A[i] / A[j])){
12 | dp[A[i]] += (dp[A[j]] * dp[A[i] / A[j]]) % Mod;
13 | }
14 | }
15 | }
16 | long ans = 0;
17 | for(auto& i: dp)
18 | ans = (ans + i.second) % Mod;
19 | return ans % Mod;
20 | }
21 | };
22 |
--------------------------------------------------------------------------------
/91. Decode Ways/91. Decode Ways.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int numDecodings(string s){
5 | vector hg(s.size()+1, 0);
6 | int ans = 0;
7 | ans = helper(s, 0, hg);
8 | return ans;
9 | }
10 | int helper(string s, int i, vector&hs) {
11 | if(s.size() == i) return 1;
12 | if(s[i] == '0') return 0;
13 | if(hs[i] > 0) return hs[i];
14 | if(i == s.size()-1) return 1;
15 | if(i < s.size()-1){
16 | int num = (s[i] - '0') * 10 + (s[i+1] - '0');
17 | if(num>0 && num<=26){
18 | return hs[i] = helper(s, i+1, hs) + helper(s, i+2, hs);
19 | }
20 | }
21 | return hs[i]=helper(s, i+1, hs);
22 | }
23 | };
24 |
--------------------------------------------------------------------------------
/98. Validate Binary Search Tree/98. Validate Binary Search Tree.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 |
5 | bool isBST(TreeNode *root, long long int min, long long int max){
6 |
7 | bool l=true,r=true;
8 | if(!root->left && !root->right){
9 | if(!(root->val >min && root->val < max))
10 | return false;
11 | else
12 | return true;
13 | }
14 | if(!(root->val >min && root->val < max))
15 | return false;
16 |
17 | if(root->left)
18 | l = isBST(root->left, min, root->val);
19 | if(root->right)
20 | r = isBST(root->right, root->val, max);
21 |
22 | return l && r;
23 | }
24 |
25 | bool isValidBST(TreeNode* root) {
26 | long long int min = (long long int)INT_MIN-1, max = (long long int)INT_MAX+1;
27 | return isBST(root,min,max);
28 | }
29 | };
30 |
--------------------------------------------------------------------------------
/42. Trapping Rain Water/42. Trapping Rain Water.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int trap(vector& height) {
5 |
6 | if (height.empty()) return 0;
7 | int trapWater = 0;
8 | int size = height.size();
9 | vector left_max(size), right_max(size);
10 | left_max[0] = height[0];
11 | for (int i = 1; i < size; i++) {
12 | left_max[i] = max(height[i], left_max[i - 1]);
13 | }
14 | right_max[size - 1] = height[size - 1];
15 | for (int i = size - 2; i >= 0; i--) {
16 | right_max[i] = max(height[i], right_max[i + 1]);
17 | }
18 | for (int i = 1; i < size - 1; i++) {
19 | trapWater += min(left_max[i], right_max[i]) - height[i];
20 | }
21 | return trapWater;
22 |
23 | }
24 | };
25 |
--------------------------------------------------------------------------------
/1338. Reduce Array Size to The Half/1338. Reduce Array Size to The Half.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | int minSetSize(vector& arr) {
5 |
6 | mapmp;
7 | for(auto i:arr){
8 | mp[i]++;
9 | }
10 |
11 | vector>use;
12 | for(auto i:mp){
13 | use.push_back({i.second,i.first});
14 | }
15 | sort(use.begin(),use.end(),greater>());
16 | int n=arr.size();
17 |
18 | int sum=0,count=0;
19 | for(int i=0;i p1, pair p2){
6 | return p1.second>> m;
10 | TimeMap() {
11 |
12 | }
13 |
14 | void set(string key, string value, int timestamp) {
15 | m[key].push_back({value, timestamp});
16 | }
17 |
18 | string get(string key, int timestamp) {
19 | auto itr = upper_bound(m[key].begin(), m[key].end(), make_pair("", timestamp), compare);
20 | if(itr == m[key].begin()){
21 | return "";
22 | }
23 |
24 | return prev(itr) -> first;
25 | }
26 | };
27 |
--------------------------------------------------------------------------------
/43. Multiply Strings/43. Multiply Strings.cpp:
--------------------------------------------------------------------------------
1 | //Author: Devendra Uraon
2 | class Solution {
3 | public:
4 | string multiply(string num1, string num2) {
5 | if(num1[0] == '0' || num2[0] == '0') return "0";
6 | vector