├── .gitignore ├── .vscode ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── Arrays ├── 01Sort.cpp ├── FindMissingAndRepeating │ └── UsingEquations.cpp ├── FindSecondMaximum │ └── Optimal.java ├── FindTheDuplicateNumber │ ├── Better.java │ └── Optimal.java ├── MajorityElement │ └── OnlyMajorityElement.java ├── MergeRange │ └── MergeRange.java ├── MergeSort │ └── MergeSort.java ├── SearchIn2DMatrix │ └── Optimal.java └── TrappingRainwater │ ├── Better.java │ └── BruteForce.java ├── Backtracking └── RatInAMaze.java ├── Binary_Search ├── FindNthRoot.java └── MedianOfTwoSortedArrays │ └── Optimal.java ├── FindMissingAndRepeatingNumber └── Good.java ├── Graphs └── Kruskal │ └── Solution.java ├── Greedy ├── FractionalKnapsack │ └── Solution.java ├── JobSequencing │ └── JobSequencingDSU.java └── Solution.java ├── LinkedList ├── FindIntersectionOfTwoLinkedList │ └── Better.java ├── FindMiddleOfLinkedList │ └── Optimal.java ├── FlattenLinkedList │ └── Optimal.java ├── Palindrome │ ├── BruteForce.java │ └── Optimal.java ├── Reverse │ └── Solution.java └── Traverse │ └── Solution.java ├── Recursion └── CombinationSums1 │ ├── Try.java │ └── test.java ├── template.cpp └── test.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | *.class -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "defines": [ 9 | "_DEBUG", 10 | "UNICODE", 11 | "_UNICODE" 12 | ], 13 | "windowsSdkVersion": "10.0.17763.0", 14 | "compilerPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\Hostx64\\x64\\cl.exe", 15 | "cStandard": "c17", 16 | "cppStandard": "c++17", 17 | "intelliSenseMode": "windows-msvc-x64" 18 | } 19 | ], 20 | "version": 4 21 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "java", 9 | "name": "Launch Optimal", 10 | "request": "launch", 11 | "mainClass": "Binary_Search.MedianOfTwoSortedArrays.Optimal", 12 | "projectName": "StriverSDESheet_e2b74240" 13 | }, 14 | { 15 | "type": "java", 16 | "name": "Launch FindNthRoot", 17 | "request": "launch", 18 | "mainClass": "Binary_Search.FindNthRoot", 19 | "projectName": "StriverSDESheet_e2b74240" 20 | }, 21 | { 22 | "type": "java", 23 | "name": "Launch Try", 24 | "request": "launch", 25 | "mainClass": "Recursion.CombinationSums1.Try", 26 | "projectName": "StriverSDESheet_fe642f3d" 27 | }, 28 | { 29 | "name": "g++.exe - Build and debug active file", 30 | "type": "cppdbg", 31 | "request": "launch", 32 | "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", 33 | "args": [], 34 | "stopAtEntry": false, 35 | "cwd": "${fileDirname}", 36 | "environment": [], 37 | "externalConsole": false, 38 | "MIMode": "gdb", 39 | "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", 40 | "setupCommands": [ 41 | { 42 | "description": "Enable pretty-printing for gdb", 43 | "text": "-enable-pretty-printing", 44 | "ignoreFailures": true 45 | } 46 | ], 47 | "preLaunchTask": "C/C++: g++.exe build active file" 48 | } 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.errorSquiggles": "Disabled", 3 | "files.associations": { 4 | "cmath": "cpp", 5 | "cstddef": "cpp", 6 | "cstdint": "cpp", 7 | "cstdio": "cpp", 8 | "cstdlib": "cpp", 9 | "cstring": "cpp", 10 | "cwchar": "cpp", 11 | "exception": "cpp", 12 | "initializer_list": "cpp", 13 | "ios": "cpp", 14 | "iosfwd": "cpp", 15 | "iostream": "cpp", 16 | "istream": "cpp", 17 | "limits": "cpp", 18 | "memory": "cpp", 19 | "new": "cpp", 20 | "ostream": "cpp", 21 | "stdexcept": "cpp", 22 | "streambuf": "cpp", 23 | "string": "cpp", 24 | "system_error": "cpp", 25 | "tuple": "cpp", 26 | "type_traits": "cpp", 27 | "typeinfo": "cpp", 28 | "utility": "cpp", 29 | "xfacet": "cpp", 30 | "xiosbase": "cpp", 31 | "xlocale": "cpp", 32 | "xlocinfo": "cpp", 33 | "xlocnum": "cpp", 34 | "xmemory": "cpp", 35 | "xmemory0": "cpp", 36 | "xstddef": "cpp", 37 | "xstring": "cpp", 38 | "xtr1common": "cpp", 39 | "xutility": "cpp", 40 | "array": "cpp", 41 | "deque": "cpp", 42 | "forward_list": "cpp", 43 | "list": "cpp", 44 | "unordered_map": "cpp", 45 | "unordered_set": "cpp", 46 | "vector": "cpp", 47 | "regex": "cpp", 48 | "valarray": "cpp", 49 | "complex": "cpp", 50 | "numeric": "cpp", 51 | "*.tcc": "cpp", 52 | "chrono": "cpp", 53 | "random": "cpp", 54 | "types.h": "c" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: g++.exe build active file", 6 | "command": "C:\\MinGW\\bin\\g++.exe", 7 | "args": [ 8 | "-g3", 9 | "-Wall", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": ["$gcc"], 18 | "group": "build", 19 | "detail": "Task generated by Debugger." 20 | }, 21 | { 22 | "type": "cppbuild", 23 | "label": "C/C++: g++.exe build active file", 24 | "command": "C:\\MinGW\\bin\\g++.exe", 25 | "args": [ 26 | "-g", 27 | "${file}", 28 | "-o", 29 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 30 | ], 31 | "options": { 32 | "cwd": "${fileDirname}" 33 | }, 34 | "problemMatcher": ["$gcc"], 35 | "group": { 36 | "kind": "build", 37 | "isDefault": true 38 | }, 39 | "detail": "compiler: C:\\MinGW\\bin\\g++.exe" 40 | } 41 | ], 42 | "version": "2.0.0" 43 | } 44 | -------------------------------------------------------------------------------- /Arrays/01Sort.cpp: -------------------------------------------------------------------------------- 1 | // Author: Ankur Saha 2 | // Linkedin: https://www.linkedin.com/in/ankur-saha/ 3 | // Github: https://github.com/Excalibur79 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define int long long int 10 | #define vi vector 11 | #define vll vector 12 | #define pii pair 13 | #define pll pair 14 | #define pb push_back 15 | #define mp make_pair 16 | const int MOD = 1e9 + 7; 17 | const ll INF = 1e18; 18 | #define inputarr(arr, n) \ 19 | for (ll i = 0; i < n; i++) cin >> arr[i]; 20 | #define printarr(arr, n) \ 21 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 22 | 23 | void solve() { 24 | vi nums = {0, 1, 2, 1, 0, 1}; 25 | int numberOfOnes = 0, numberOfTwos = 0, numberOfZeroes = 0; 26 | for (int value : nums) { 27 | if (value == 0) 28 | numberOfZeroes++; 29 | else if (value == 1) 30 | numberOfOnes++; 31 | else 32 | numberOfTwos++; 33 | } 34 | int k = 0; 35 | while (numberOfZeroes--) nums[k++] = 0; 36 | while (numberOfOnes--) nums[k++] = 1; 37 | while (numberOfTwos--) nums[k++] = 2; 38 | 39 | printarr(nums, nums.size()); 40 | } 41 | 42 | int32_t main() { 43 | ios_base::sync_with_stdio(false); 44 | cin.tie(0); 45 | cout.tie(0); 46 | int t = 1; 47 | // cin >> t; 48 | while (t--) { 49 | solve(); 50 | } 51 | return 0; 52 | } -------------------------------------------------------------------------------- /Arrays/FindMissingAndRepeating/UsingEquations.cpp: -------------------------------------------------------------------------------- 1 | vector missing_repeated_number(const vector &A) { 2 | long long int len = A.size(); 3 | 4 | long long int S = (len * (len + 1)) / 2; 5 | long long int P = (len * (len + 1) * (2 * len + 1)) / 6; 6 | long long int missingNumber = 0, repeating = 0; 7 | 8 | for (int i = 0; i < A.size(); i++) { 9 | S -= (long long int)A[i]; 10 | P -= (long long int)A[i] * (long long int)A[i]; 11 | } 12 | 13 | missingNumber = (S + P / S) / 2; 14 | 15 | repeating = missingNumber - S; 16 | 17 | vector ans; 18 | 19 | ans.push_back(repeating); 20 | ans.push_back(missingNumber); 21 | 22 | return ans; 23 | } -------------------------------------------------------------------------------- /Arrays/FindSecondMaximum/Optimal.java: -------------------------------------------------------------------------------- 1 | package Arrays.FindSecondMaximum; 2 | public class Optimal { 3 | public static void main(String[] args) { 4 | int arr[] = {1,0,7,7,1}; 5 | int secondMax = -1; 6 | int firstMax = arr[0]; 7 | for(int data:arr){ 8 | if(data>firstMax){ 9 | secondMax=firstMax; 10 | firstMax = data; 11 | } 12 | else if(data>secondMax && data hash = new HashMap<>(); 6 | for(int data:nums){ 7 | if(hash.containsKey(data)) 8 | hash.put(data,hash.get(data)+1); 9 | else 10 | hash.put(data,1); 11 | } 12 | for(HashMap.Entry data:hash.entrySet()){ 13 | if(data.getValue()>1) 14 | return data.getKey(); 15 | } 16 | return 1; 17 | 18 | 19 | } 20 | } 21 | 22 | public class Better { 23 | public static void main(String[] args) { 24 | Solution obj= new Solution(); 25 | int arr[] = {1,2,3,4,3}; 26 | System.out.println( obj.findDuplicate(arr)); 27 | } 28 | } -------------------------------------------------------------------------------- /Arrays/FindTheDuplicateNumber/Optimal.java: -------------------------------------------------------------------------------- 1 | package Arrays.FindTheDuplicateNumber; 2 | 3 | class Solution{ 4 | int findDuplicate(int arr[]){ 5 | int slow = arr[0],fast=arr[0]; 6 | int ans=0; 7 | do{ 8 | slow=arr[slow]; 9 | fast=arr[arr[fast]]; 10 | }while(slow!=fast); 11 | 12 | fast=arr[0]; 13 | while(slow!=fast){ 14 | slow=arr[slow]; 15 | fast=arr[fast]; 16 | } 17 | 18 | return slow; 19 | } 20 | } 21 | 22 | public class Optimal { 23 | public static void main(String[] args) { 24 | Solution obj = new Solution(); 25 | int arr[] = {1,2,3,4,3}; 26 | System.out.println( obj.findDuplicate(arr)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Arrays/MajorityElement/OnlyMajorityElement.java: -------------------------------------------------------------------------------- 1 | package Arrays.MajorityElement; 2 | 3 | 4 | public class OnlyMajorityElement { 5 | 6 | public static int majorityElement(int arr[]){ 7 | int num=-1,count=0; 8 | for(int data:arr){ 9 | // System.out.println(num); 10 | if(count==0) 11 | num=data; 12 | if(data==num) 13 | count++; 14 | else{ 15 | count--; 16 | // if(count==0) 17 | // num=data; 18 | } 19 | } 20 | return num; 21 | } 22 | 23 | public static void main(String[] args) { 24 | int arr[] = {1,2,3,3,4,6,3,1,2}; 25 | int ans = majorityElement(arr); 26 | System.out.println(ans); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /Arrays/MergeRange/MergeRange.java: -------------------------------------------------------------------------------- 1 | package Arrays.MergeRange; 2 | import java.util.*; 3 | class Solution { 4 | public int[][] merge(int[][] intervals) { 5 | Arrays.sort(intervals,(a,b)->a[0]-b[0]); 6 | ArrayList ans = new ArrayList<>(); 7 | ans.add(intervals[0]); 8 | for(int i=1;i=0;i--){ 18 | rightMaxArray[i] = Math.max(height[i],rightMaxArray[i+1]); 19 | } 20 | 21 | //calculating rain traps 22 | for(int i=0;iheight[rightMax]?j:rightMax; 13 | } 14 | //finding left 15 | for(int j=i-1;j>=0;j--){ 16 | leftMax = height[j]>height[leftMax]?j:leftMax; 17 | } 18 | if(leftMax!=-1 && rightMax!=-1){ 19 | // System.out.println(Math.min(height[leftMax],height[rightMax]) - height[i]+" "+i); 20 | ans+=Math.min(height[leftMax],height[rightMax]) - height[i]; 21 | } 22 | } 23 | return ans; 24 | } 25 | public static void main(String[] args) { 26 | System.out.println(trap(new int[]{4,2,0,3,2,5})); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /Backtracking/RatInAMaze.java: -------------------------------------------------------------------------------- 1 | package Backtracking; 2 | 3 | public class RatInAMaze { 4 | public static int m,n; 5 | public static void compute(int[][] maze,int[][] soln,int i,int j ){ 6 | if(i==m-1 && j==n-1){ 7 | for(int row[]:soln){ 8 | for(int cell:row) 9 | System.out.print(cell+" "); 10 | System.out.println(); 11 | } 12 | System.out.println(); 13 | } 14 | //bottom check 15 | if(i+1<=m-1 && maze[i+1][j]==1){ 16 | soln[i+1][j] = 1; 17 | compute(maze,soln,i+1,j); 18 | soln[i+1][j]=0; 19 | } 20 | if(j+1<=n-1 && maze[i][j+1]==1){ 21 | soln[i][j+1]=1; 22 | compute(maze,soln,i,j+1); 23 | soln[i][j+1] = 0; 24 | } 25 | } 26 | public static void main(String[] args) { 27 | int maze[][] = {{1, 0, 0, 0}, 28 | {1, 1, 0, 1}, 29 | {1, 1, 0, 0}, 30 | {0, 1, 1, 1}}; 31 | int soln[][] = {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}; 32 | soln[0][0] = 1; 33 | m = maze.length; 34 | n = maze[0].length; 35 | compute(maze,soln,0,0); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /Binary_Search/FindNthRoot.java: -------------------------------------------------------------------------------- 1 | package Binary_Search; 2 | 3 | import java.io.*; 4 | 5 | class Solution { 6 | 7 | static double eps = 1e-6; 8 | 9 | public static double multiply(double mid, int n) { 10 | double res = 1.0; 11 | for (int i = 1; i <= n; i++) res *= mid; 12 | return res; 13 | } 14 | 15 | public static double findNthRootOfM(int n, long val) { 16 | double l = 1, h = val; 17 | while ((h - l) > eps) { 18 | double mid = (l + h) / 2.0; 19 | System.out.println(mid); 20 | if (multiply(mid, n) < val) { 21 | l = mid; 22 | } else h = mid; 23 | } 24 | return l; 25 | } 26 | } 27 | 28 | public class FindNthRoot { 29 | 30 | public static void main(String args[]) throws IOException { 31 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 32 | 33 | int n = Integer.parseInt(br.readLine()); 34 | long val = Long.parseLong(br.readLine()); 35 | double ans = Solution.findNthRootOfM(n, val); 36 | System.out.println(ans); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Binary_Search/MedianOfTwoSortedArrays/Optimal.java: -------------------------------------------------------------------------------- 1 | package Binary_Search.MedianOfTwoSortedArrays; 2 | 3 | public class Optimal { 4 | 5 | public static void main(String[] args) { 6 | int nums1[] = { 1, 2 }; 7 | int nums2[] = { 3, 4 }; 8 | 9 | int n1 = nums1.length; 10 | int n2 = nums2.length; 11 | int low = 0; 12 | int high = n1; //because max cut is selecting no elements from arr1 13 | 14 | while (low <= high) { 15 | int cut1 = (low + high) / 2; 16 | int cut2 = (n1 + n2 + 1) / 2 - cut1; 17 | 18 | int left1 = cut1 == 0 ? Integer.MIN_VALUE : nums1[cut1 - 1]; //{1 3 4 | 7 10 12} this is cut1 19 | int left2 = cut2 == 0 ? Integer.MIN_VALUE : nums2[cut2 - 1]; // {2 | 3 6 15} this is cut2 20 | 21 | int right1 = cut1 == n1 ? Integer.MAX_VALUE : nums1[cut1]; 22 | int right2 = cut2 == n2 ? Integer.MAX_VALUE : nums2[cut2]; 23 | 24 | //checking the cross condition 25 | if (left1 <= right2 && left2 <= right1) { 26 | if ((n1 + n2) % 2 == 0) { 27 | System.out.println( 28 | Math.max(left1, left2) + " " + Math.min(right1, right2) 29 | ); 30 | System.out.println( 31 | (Math.max(left1, left2) + Math.min(right1, right2)) / 2.0 32 | ); 33 | return; 34 | } else { //odd length total so only one median 35 | System.out.println(Math.max(left1, left2)); 36 | return; 37 | } 38 | } else if (left1 > right2) { 39 | high = cut1 - 1; 40 | } else low = cut1 + 1; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /FindMissingAndRepeatingNumber/Good.java: -------------------------------------------------------------------------------- 1 | package FindMissingAndRepeatingNumber; 2 | 3 | 4 | public class Good { 5 | public static void main(String[] args) { 6 | 7 | } 8 | 9 | } -------------------------------------------------------------------------------- /Graphs/Kruskal/Solution.java: -------------------------------------------------------------------------------- 1 | package Graphs.Kruskal; 2 | import java.util.*; 3 | 4 | class Edge{ 5 | int u; 6 | int v; 7 | int wt; 8 | Edge(int u,int v,int wt){ 9 | this.u = u; 10 | this.v = v; 11 | this.wt = wt; 12 | } 13 | } 14 | 15 | class edgeComparator implements Comparator{ 16 | @Override 17 | public int compare(Edge a,Edge b){ 18 | return a.wt-b.wt; 19 | } 20 | } 21 | 22 | public class Solution { 23 | public static List edges=new ArrayList<>(); 24 | public static int parent[] = new int[1000]; 25 | public static int rank[] = new int[1000]; 26 | 27 | static void makeSet(){ 28 | for(int i=0;irank[v]){ 45 | parent[v] = u; 46 | } 47 | else if(rank[v]>rank[u]){ 48 | parent[u] = v; 49 | } 50 | else{ 51 | parent[v] = u; 52 | rank[u]++; 53 | } 54 | } 55 | 56 | public static void main(String[] args) { 57 | // int arr[][] = {{7,6,1},{8,2,2},{6,5,2},{0,1,4},{2,5,4}, 58 | // {8,6,6},{2,4,7},{7,8,8},{0,7,8},{1,2,8},{3,4,9},{5,4,10}, 59 | // {1,7,11},{3,5,14}}; 60 | int arr[][] = {{0,1,10},{0,2,6},{0,3,5},{1,3,15},{2,3,4}}; 61 | makeSet(); 62 | for(int data[]:arr){ 63 | edges.add(new Edge(data[0],data[1],data[2])); 64 | } 65 | Collections.sort(edges,new edgeComparator()); 66 | List ans = new ArrayList<>(); 67 | int wt=0; 68 | for(Edge edge:edges){ 69 | if(find(edge.u)!=find(edge.v)){ 70 | merge(edge.u,edge.v); 71 | ans.add(edge); 72 | wt+=edge.wt; 73 | } 74 | } 75 | for(Edge ansEdge:ans){ 76 | System.out.println(ansEdge.u+"---"+ansEdge.v+" : "+ansEdge.wt); 77 | } 78 | System.out.println(wt); 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Greedy/FractionalKnapsack/Solution.java: -------------------------------------------------------------------------------- 1 | package Greedy.FractionalKnapsack; 2 | import java.util.*; 3 | 4 | class Item { 5 | int value, weight; 6 | Item(int x, int y){ 7 | this.value = x; 8 | this.weight = y; 9 | } 10 | } 11 | 12 | class itemComparator implements Comparator{ 13 | @Override 14 | public int compare(Item a,Item b){ 15 | return (int)((double)b.value/b.weight - (double)a.value/a.weight); 16 | } 17 | } 18 | 19 | class Solution 20 | { 21 | //Function to get the maximum total value in the knapsack. 22 | public static double fractionalKnapsack(int W, Item arr[], int n) 23 | { 24 | Arrays.sort(arr,new itemComparator()); 25 | double ans=0; 26 | for(Item item:arr){ 27 | if(W>0){ 28 | if(item.weight<=W){ 29 | ans+=item.value; 30 | W-=item.weight; 31 | } 32 | else{ 33 | ans+=((double)item.value/item.weight)*(W); 34 | } 35 | } 36 | else break; 37 | } 38 | return ans; 39 | } 40 | 41 | public static void main(String[] args) { 42 | Solution obj = new Solution(); 43 | Scanner sc = new Scanner(System.in); 44 | int n,w; 45 | n = sc.nextInt(); 46 | w = sc.nextInt(); 47 | Item arr[] = new Item[n]; 48 | for(int i=0;ib[1]-a[1]); 31 | makeSet(1000); 32 | int ans=0; 33 | for(int job[]:jobs){ 34 | int d = Math.min(jobs.length,job[0]); 35 | d = find(d); 36 | if(d>0){ 37 | union(d-1,d); 38 | ans+=job[1]; 39 | } 40 | } 41 | System.out.println(ans); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Greedy/Solution.java: -------------------------------------------------------------------------------- 1 | package Greedy; 2 | import java.util.*; 3 | 4 | class meeting{ 5 | int start; 6 | int end; 7 | int pos; 8 | meeting(int start,int end,int pos){ 9 | this.start = start; 10 | this.end = end; 11 | this.pos=pos; 12 | } 13 | } 14 | 15 | class meetingComparator implements Comparator{ 16 | @Override 17 | public int compare(meeting a,meeting b){ 18 | if(a.end==b.end) 19 | return a.start-b.start; 20 | return a.end-b.end; 21 | } 22 | } 23 | 24 | public class Solution { 25 | public static int maximumMeetings(int[] start, int[] end) { 26 | List ans = new ArrayList<>(); 27 | if(start.length==0){ 28 | ans.add(0); 29 | return ans.size(); 30 | } 31 | List meetings = new ArrayList<>(); 32 | for(int i=0;icurMeeting.end){ 40 | curMeeting = meetings.get(i); 41 | System.out.println("meet : "+curMeeting.start+" "+curMeeting.end); 42 | ans.add(curMeeting.pos); 43 | } 44 | } 45 | return ans.size(); 46 | } 47 | 48 | public static void main(String[] args) { 49 | int start[] = {0,7,1,4,8}; 50 | int end[] = {2,9,5,9,10}; 51 | int res = maximumMeetings(start, end); 52 | System.out.println(res); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /LinkedList/FindIntersectionOfTwoLinkedList/Better.java: -------------------------------------------------------------------------------- 1 | package LinkedList.FindIntersectionOfTwoLinkedList; 2 | import java.util.Set; 3 | import java.util.HashSet; 4 | 5 | class ListNode{ 6 | int val; 7 | ListNode next; 8 | ListNode() {} 9 | ListNode(int val) { this.val = val; } 10 | ListNode(int val, ListNode next) { this.val = val; this.next = next; } 11 | } 12 | 13 | public class Better { 14 | 15 | public static ListNode getIntersectionNode(ListNode headA, ListNode headB) { 16 | Set set = new HashSet<>(); 17 | while(headA!=null){ 18 | set.add(headA); 19 | headA=headA.next; 20 | } 21 | while(headB!=null){ 22 | if(set.contains(headB)) 23 | return headB; 24 | headB=headB.next; 25 | } 26 | return null; 27 | } 28 | public static void main(String[] args) { 29 | getIntersectionNode(headA, headB) 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /LinkedList/FindMiddleOfLinkedList/Optimal.java: -------------------------------------------------------------------------------- 1 | package LinkedList.FindMiddleOfLinkedList; 2 | 3 | 4 | class ListNode{ 5 | int val; 6 | ListNode next; 7 | ListNode(){ 8 | this.val=0; 9 | this.next=null; 10 | } 11 | ListNode(int val){ 12 | this.val=val; 13 | this.next = null; 14 | } 15 | ListNode(int val,ListNode next){ 16 | this.val = val; 17 | this.next = next; 18 | } 19 | } 20 | 21 | public class Optimal { 22 | ListNode list; 23 | 24 | public static ListNode createList(int arr[]){ 25 | ListNode tailing = new ListNode(arr[0]); 26 | ListNode head = tailing; 27 | for(int i=1;i reversed = new Stack<>(); 7 | ListNode start = head; 8 | while(head!=null){ 9 | reversed.push(head); 10 | head=head.next; 11 | } 12 | while(start!=null){ 13 | if(reversed.isEmpty()) 14 | return false; 15 | ListNode node = reversed.pop(); 16 | if(node.val!=start.val) 17 | return false; 18 | start=start.next; 19 | } 20 | return true; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LinkedList/Palindrome/Optimal.java: -------------------------------------------------------------------------------- 1 | package LinkedList.Palindrome; 2 | 3 | 4 | class ListNode{ 5 | int val; 6 | ListNode next; 7 | ListNode(){ 8 | this.val=0; 9 | this.next=null; 10 | } 11 | ListNode(int val){ 12 | this.val=val; 13 | this.next = null; 14 | } 15 | ListNode(int val,ListNode next){ 16 | this.val = val; 17 | this.next = next; 18 | } 19 | } 20 | 21 | public class Optimal { 22 | ListNode list; 23 | 24 | public static ListNode createList(int arr[]){ 25 | ListNode tailing = new ListNode(arr[0]); 26 | ListNode head = tailing; 27 | for(int i=1;i> ans=new ArrayList<>(); 8 | public static List combination = new ArrayList<>(); 9 | 10 | public static void recur(int candidates[],int target,int n ){ 11 | if(target==0){ 12 | ans.add(combination); 13 | return; 14 | } 15 | if(n==1 && target%candidates[n-1]==0){ 16 | for(int i=0;i 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define int long long int 10 | #define vi vector 11 | #define vll vector 12 | #define pii pair 13 | #define pll pair 14 | #define pb push_back 15 | #define mp make_pair 16 | const int MOD = 1e9 + 7; 17 | const ll INF = 1e18; 18 | #define inputarr(arr, n) \ 19 | for (ll i = 0; i < n; i++) cin >> arr[i]; 20 | #define printarr(arr, n) \ 21 | for (ll i = 0; i < n; i++) cout << arr[i] << ' '; 22 | 23 | void solve() {} 24 | 25 | int32_t main() { 26 | ios_base::sync_with_stdio(false); 27 | cin.tie(0); 28 | cout.tie(0); 29 | int t = 1; 30 | // cin >> t; 31 | while (t--) { 32 | solve(); 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /test.java: -------------------------------------------------------------------------------- 1 | 2 | public class test { 3 | public static void main(String[] args) { 4 | System.out.println((double)5/4); 5 | } 6 | 7 | } --------------------------------------------------------------------------------