Skip to content

Solutions of data structures and algorithmic problems in different online judge platforms.

Notifications You must be signed in to change notification settings

MarufHassan/algorithmic-problem-solving

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data Structure and Algorithmic Problems

This repository consists of my solution of algorithm and data structures problems in different online judge platforms i.e LeetCode, Hackerrank, UVA, CodeForces, GFG. 80% of the problems have been solved using Java, rest are C and C++.

Although I solved many more problems in these platforms, I only documented these solutions.

List of problems

All the problems are categorized by the respective online judge. You can access the problem and the solution directly from the link.

Geeks for Geeks (GFG)

Practice problems from Geek for Geek in Java. All the codes are tested in online-judge. Some problems are not solved yet.

LeetCode

Solved problems from Leetcode using Java. All the codes are tested in online-judge.

Easy

# Title Tag
1 Two Sum Array, Hash Table
7 Reverse Integer Math
9 Palindrome Number Math
13 Roman to Integer Math, String
14 Longest Common Prefix String
20 Valid Parentheses String, Stack
21 Merge Two Sorted Lists Linked List
26 Implement strStr() String
26 Remove Duplicates from Sorted Array Array, Two Pointers
27 Remove Element Array, Two Pointers
35 Search Insert Position Binary Search
53 Maximum Subarray Array
58 Length of Last Word String
67 Add Binary String
69 Sqrt(x) Binary Search
83 Remove Duplicates from Sorted List Linked List
88 Merge Sorted Array Array, Two Pointers
100 Same Tree Tree
101 Symmetric Tree Tree
104 Maximum Depth of Binary Tree Tree
107 Binary Tree Level Order Traversal II Tree
108 Convert Sorted Array to Binary Search Tree Tree
110 Balanced Binary Tree Tree
111 Minimum Depth of Binary Tree Tree
112 Path Sum Tree
118 Pascal's Triangle Array
121 Best Time to Buy and Sell Stock Array, Dynamic Programming
125 Valid Palindrome String
136 Single Number Hash Table, Bit Manipulation
141 Linked List Cycle Linked List
155 Min Stack Stack
160 Intersection of Two Linked Lists Linked List
167 Two Sum II - Input array is sorted Array, Two Pointers, Binary Search
189 Rotate Array Array
203 Remove Linked List Elements Linked List
205 Isomorphic Strings Hash Table
206 Reverse Linked List Linked List
215 Kth Largest Element in an Array Heap
217 Contains Duplicate Hash Table
219 Contains Duplicate II Array, Hash Table
225 Implement Stack using Queues Stack
226 Invert Binary Tree Tree
232 Implement Queue using Stacks Stack
234 Palindrome Linked List Linked List
235 Lowest Common Ancestor of a Binary Search Tree Tree
237 Delete Node in a Linked List Linked List
242 Valid Anagram Hash Table, Sort
257 Binary Tree Paths Tree
268 Missing Number Array, Math, Bit Manipulation
278 First Bad Version Array
283 Move Zeroes Array, Two Pointers
290 Word Pattern Hash Table
344 Reverse String String
345 Reverse Vowels of a String String
349 Intersection of Two Arrays Hash Table, Sort, Two Pointers, Binary Search
350 Intersection of Two Arrays II Hash Table, Sort, Two Pointers
367 Valid Perfect Square Binary Search
383 Ransom Note String
387 First Unique Character in a String String
401 Binary Watch Backtracking
404 Sum of Left Leaves Tree
414 Third Maximum Number Array
415 Add Strings String
429 N-ary Tree Level Order Traversal Tree
434 Number of Segments in a String String
437 Path Sum III Tree
443 String Compression String
448 Find All Numbers Disappeared in an Array Array
459 Repeated Substring Pattern String
463 Island Perimeter Hash Table
485 Max Consecutive Ones Array, Two Pointers
496 Next Greater Element I Stack
500 Keyboard Row Hash Table
501 Find Mode in Binary Search Tree Tree
509 Fibonacci Number Array, Math
520 Detect Capital String
538 Convert BST to Greater Tree Tree
541 Reverse String II String
543 Diameter of Binary Tree Tree
551 Student Attendance Record I String
557 Reverse Words in a String III String
559 Maximum Depth of N-ary Tree Tree
563 Binary Tree Tilt Tree
572 Subtree of Another Tree Tree
575 Distribute Candies Hash Table
589 N-ary Tree Preorder Traversal Tree
590 N-ary Tree Postorder Traversal Tree
617 Merge Two Binary Trees Tree
637 Average of Levels in Binary Tree Tree
645 Set Mismatch Hash Table
653 Two Sum IV - Input is a BST Tree
657 Robot Return to Origin String
669 Trim a Binary Search Tree Tree
680 Valid Palindrome II String
682 Baseball Game Stack
686 Repeated String Match String
687 Longest Univalue Path Tree
690 Employee Importance Hash Table, Depth First Search
696 Count Binary Substrings String
700 Search in a Binary Search Tree Tree
703 Kth Largest Element in a Stream Heap
704 Binary Search Binary Search
705 Design HashSet Hash Table
706 Design HashMap Hash Table
707 Design Linked List Linked List
709 To Lower Case String
720 Longest Word in Dictionary Trie
733 Flood Fill Depth First Search
747 Largest Number At Least Twice of Others Array
748 Shortest Completing Word Hash Table
771 Jewels and Stones HashTable
784 Letter Case Permutation Backtracking
804 Unique Morse Code Words String
811 Subdomain Visit Count Hash Table
819 Most Common Word String
824 Goat Latin String
832 Flipping an Image Array
844 Backspace String Compare Stack
852 Peak Index in a Mountain Array Binary Search
859 Buddy Strings String
867 Transpose Matrix Array
872 Leaf-Similar Trees Tree
876 Middle of the Linked List Linked List
884 Uncommon Words from Two Sentences Hash Table
893 Groups of Special-Equivalent Strings String
896 Monotonic Array Array
897 Increasing Order Search Tree Tree
905 Sort Array By Parity Array
917 Reverse Only Letters String, Two Pointers
922 Sort Array By Parity II Array
925 Long Pressed Name String
929 Unique Email Addresses String
937 Reorder Log Files String, Sorting
941 Valid Mountain Array Array
944 Delete Columns to Make Sorted Greedy
949 Largest Time for Given Digits Math
953 Verifying an Alien Dictionary Sorting
965 Univalued Binary Tree Tree
970 Powerful Integers Math
973 K Closest Points to Origin Math
976 Largest Perimeter Triangle Math, Sorting
978 Longest Turbulent Subarray Array, Two Pointers, Sort
984 String Without AAA or BBB Greedy
985 Sum of Even Numbers After Queries Array
989 Add to Array-Form of Integer Array
993 Cousins in Binary Tree Tree
994 Rotting Oranges Breadth First Search
997 Find the Town Judge Graph
999 Available Captures for Rook Array
1002 Find Common Characters Array
1005 Maximize Sum Of Array After K Negations Greedy
1012 Complement of Base 10 Integer Math
1013 Partition Array Into Three Parts With Equal Sum Array
1013 Pairs of Songs With Total Durations Divisible by 60 Array
1018 Binary Prefix Divisible By 5 Array
1022 Sum of Root To Leaf Binary Numbers Tree
1030 Matrix Cells in Distance Order Sort
1037 Valid Boomerang Math

Medium

# Title Tag
2 Add Two Numbers Linked List
8 String to Integer (atoi) Math, String
11 Container With Most Water Array
12 Integer to Roman Math, String
17 Letter Combinations of a Phone Number String, Backtracking
22 Generate Parentheses String, Backtracking
34 Find First and Last Position of Element in Sorted Array Array
43 Multiply Strings String
46 Permutations Backtracking
48 Rotate Image Array
49 Group Anagrams String
56 Merge Intervals Array, Sort
75 Sort Colors Two Pointers, Sorting
78 Subsets Backtracking
94 Binary Tree Inorder Traversal Tree
98 Validate Binary Search Tree Tree
102 Binary Tree Level Order Traversal Tree
103 Binary Tree Zigzag Level Order Traversal Tree
105 Construct Binary Tree from Preorder and Inorder Traversal Tree
106 Construct Binary Tree from Inorder and Postorder Traversal Tree
113 Path Sum II Tree
114 Flatten Binary Tree to Linked List Tree
116 Populating Next Right Pointers in Each Node Tree
117 Populating Next Right Pointers in Each Node II Tree
129 Sum Root to Leaf Numbers Tree
150 Evaluate Reverse Polish Notation String, Stack
173 Binary Search Tree Iterator Tree
207 Course Schedule DFS, Topological Sort
208 Implement Trie (Prefix Tree) Trie
210 Course Schedule II DFS, Topological Sort
211 Add and Search Word - Data structure design Trie
222 Count Complete Tree Nodes Tree
227 Basic Calculator II Stack, String
236 Lowest Common Ancestor of a Binary Tree Tree
238 Product of Array Except Self Array
287 Find the Duplicate Number Binary Search
334 Increasing Triplet Subsequence Array
341 Flatten Nested List Iterator Stack, Design
347 Top K Frequent Elements Heap, Hash Table
373 Find K Pairs with Smallest Sums Heap
394 Decode String Stack
442 Find All Duplicates in an Array Array
445 Add Two Numbers II Linked List
450 Delete Node in a BST Tree
451 Sort Characters By Frequency Heap, Hash Table
495 Teemo Attacking Array
503 Next Greater Element II Stack
508 Most Frequent Subtree Sum Hash Table, Tree
513 Find Bottom Left Tree Value Tree
515 Find Largest Value in Each Tree Row Tree
524 Longest Word in Dictionary through Deleting Two Pointers, String
525 Contiguous Array Hash Table
526 Beautiful Arrangement Backtracking
537 Complex Number Multiplication String
539 Minimum Time Difference String
547 Friend Circles Union Find
609 Find Duplicate File in System String
622 Design Circular Queue Queue
623 Add One Row to Tree Tree
641 Design Circular Deque Queue
648 Replace Words Trie
654 Maximum Binary Tree Tree
676 Implement Magic Dictionary Trie
677 Map Sum Pairs Trie
692 Top K Frequent Words Heap, Hash Table
695 Max Area of Island Array, DFS
701 Insert into a Binary Search Tree Tree
729 My Calendar I Array
739 Daily Temperatures Stack
785 Is Graph Bipartite? DFS, BFS, Graph
791 Custom Sort String String
802 Find Eventual Safe States Depth First Search, Graph
833 Find And Replace in String String
841 Keys and Rooms Graph, DFS
848 Shifting Letters String
875 Koko Eating Bananas Array, Binary Search
881 Boats to Save People Two Pointers
889 Construct Binary Tree from Preorder and Postorder Traversal Tree
890 Find and Replace Pattern String
900 RLE Iterator Array
904 Fruit Into Baskets Two pointers, Sliding Window
911 Online Election Binary Search
916 Word Subsets String
921 Minimum Add to Make Parentheses Valid Stack
934 Shortest Bridge Depth First Search, Breadth First Search
945 Minimum Increment to Make Array Unique Array
946 Validate Stack Sequences Stack
950 Reveal Cards In Increasing Order Array, Queue
958 check-completeness-of-a-binary-tree Tree
962 Maximum Width Ramp Array
966 Vowel Spellchecker String
978 Longest Turbulent Subarray Array
981 Time Based Key-Value Store Hash Table, Binary Search
988 Smallest String Starting From Leaf Tree
998 Maximum Binary Tree II Tree
1003 Check If Word Is Valid After Substitutions Stack
1004 Max Consecutive Ones III Two Pointers
1007 Minimum Domino Rotations For Equal Row Array, Greedy
1008 Construct Binary Search Tree from Preorder Traversal Tree
1014 Capacity To Ship Packages Within D Days Array, Binary Search
1016 Binary String With Substrings Representing 1 To N String
1019 Next Greater Node In Linked List Linked List, Stack
1023 Camelcase Matching String
1038 Binary Search Tree to Greater Sum Tree Binary Search Tree

Hard

# Title Tag
42 Trapping Rain Water Array, Two Pointers, Stack
224 Basic Calculator Math, Stack, String

Hackerrank

Solved problems from Hackerrank using Java. All the codes are tested in online-judge.

Easy

Title Tag
Minimum Absolute Difference in an Array Array, Greedy
Luck Balance Greedy
Strings: Making Anagrams String
Arrays: Left Rotation Arrays
Quicksort 1 - Partition Sorting
Counting Sort 1 Sorting
Counting Sort 2 Sorting
Equal Stack Stack
Detect a Cycle Linked List
Reverse a doubly linked list Linked List
Insert a node at a specific position in a linked list Linked List
Inserting a Node Into a Sorted Doubly Linked List Linked List
Find Merge Point of Two Lists Linked List
Print the Elements of a Linked List Linked List
Insert a Node at the Tail of a Linked List Linked List
Insert a node at the head of a linked list Linked List
Delete a Node Linked List
Print in Reverse Linked List
Reverse a linked list Linked List
Merge two sorted linked lists Linked List
Get Node Value Linked List
Compare two linked lists Linked List
Delete duplicate-value nodes from a sorted linked list Linked List
Jesse and Cookies Heap
QHEAP1 Heap
2D Array - DS Array
Height of a Binary Tree Tree

Medium

Title Tag
Greedy Florist Greedy
Max Min Greedy
Balanced Brackets Stack
Pairs Search
The Full Counting Sort Sorting, String
Queues: A Tale of Two Stacks Stack
Cycle Detection Linked List
Sparse Arrays Arrays
Sorting: Comparator Sorting
Is This a Binary Search Tree? Trees

Hard

Title Tag

UVA Online Judge

Solved problems from UVA using C, C++, Java. All the codes are tested in online-judge.

# Title Tag
119 Greedy gift givers
272 Tex quotes
290 Palindroms smordnilap
294 Divisors
325 Identifying legal pascal real constants
336 A node too far
343 What base is this
355 The bases are loaded
374 Big mod
389 Basically speaking
401 Palindromes
417 Word index
424 Integer inquiry
444 Encoder and decoder
446 Kibbles n bits n bits n bits
458 The decoder
459 Graph connectivity
465 Overflow
482 Permutation arrays
483 Word scramble
490 Rotating sentences
492 Pig latin
494 Kindergarten counting game
499 What's the frequency, kenneth
532 Dungeon master
543 Goldbach's conjecture
572 Oil deposits
573 The snail
591 Box of bricks
621 Secret research
623 500!
661 Blowing fuses
686 Goldbach's conjecture (ii)
713 Adding reversed numbers
725 Division
784 Maze exploration
785 Grid colouring
793 Network connections
865 Substitution cypher
902 Password search
978 Lemmings battle!
1124 Celebrity jeopardy
1197 The suspects
1225 Digit counting
1230 Modex
10004 Bicoloring
10008 What's cryptanalysis
10018 Reverse and add
10019 Funny encryption method
10034 Freckles
10035 Primary arithmetic
10038 Jolly jumpers
10062 Tell me the frequencies!
10070 Leap year or not leap year
10114 Loansome car buyer
10140 Prime distance
10220 I love big numbers!
10222 Decode the mad man
10235 Simply emirp
10252 Common permutation
10260 Soundex
10281 Average speed
10293 Word length and frequency
10324 Zeros and ones
10338 Mischievous children
10346 Peter's smokes
10370 Above average
10374 Election
10393 The one handed typist
10420 List of conquests
10424 Love calculator
10473 Simple base conversion
10474 Where is the marble
10523 Very easy
10524 Matrix reloaded
10551 Basic remains
10583 Ubiquitous religions
10591 Happy number
10608 Friends
10611 The playboy chimp
10685 Nature
10789 Prime frequency
10815 Andy's first dictionary
10878 Decode the tape
10892 Lcm cardinality
10919 Prerequisites
10921 Find the telephone
10929 You can say 11
10945 Mother bear
10963 The swallowing ground
11044 Searching for nessy
11059 Maximum product
11062 Andy's second dictionary
11080 Place the guards
11136 Hoax or what
11185 Ternary
11192 Group reverse
11220 Decoding the message
11278 One handed typist
11332 Summing digits
11340 Newspaper
11364 Parking
11388 Gcd lcm
11396 Claw decomposition
11417 Gcd
11462 Age sort
11498 Division of nlogonia
11530 Sms typing
11541 Decoding
11559 Event planning
11577 Letter frequency
11586 Train tracks
11608 No problem!
11631 Dark roads
11650 Mirror clock
11661 Burger time
11677 Alarm clock
11679 Sub prime
11710 Expensive subway
11713 Abstract names
11715 Car
11716 Digital fortress
11723 Numbering roads
11747 Heavy cycle edges
11764 Jumping mario
11799 Horror dash
11805 Bafana bafana
11827 Maximum gcd
11831 Sticker collector robot
11849 Cd
11850 Alaska
11875 Brick game
11877 The coco cola store
11879 Multiple of 11
11879 Multiple of 17
11942 Lumberjack sequencing
11946 Code number
11952 Arithmetic
11965 Extra spaces
12015 Google is feeling lucky
12049 Just prune the list
12136 Schedule of a married man
12149 Feynman
12279 Emoogle balance
12342 Tax calculator
12468 Zapping
12478 Hardest problem ever (easy)
12502 Three families
12503 Robot instructions
12527 Different digits
12554 A special happy birthday song!!!

Codeforces

Solved problems from Codeforces using Java. All the codes are tested in online-judge.

# Title Tag
1081A Definite Game Math
1084A The Fair Nut and Elevator Brute Force
1084B Kvass and the Fair Nut Greedy
1087A Right-Left Cipher String
1088A Ehab and another construction problem Brute Force, Constructive
1088B Ehab and subtraction Sorting
1092A Uniform String String
1092B Teams Forming Sorting
1093A Dice Rolling Math
1093B Letters Rearranging Greedy, Sortings
1097A Gennady and a Card Game Brute Force
1097B Petr and a Combination Lock Bitmasks, Brute Force
1099A Snowball Brute Force
1102A Integer Sequence Dividing Math