Skip to content

Commit

Permalink
Added codes for 15 June
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Jun 15, 2024
1 parent 1b53c78 commit a30d802
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
51 changes: 51 additions & 0 deletions GeeksForGeeks/June/15-6-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//{ Driver Code Starts
// Initial Template for Java

import java.io.*;
import java.util.*;

class GfG {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
Solution ob = new Solution();
System.out.println(ob.getCount(n));
}
}
}
// } Driver Code Ends


// User function Template for Java

class Solution {
public long getCount(int n) {
// Your code goes here
long[][] dp = new long[n][10];
for(int i=0;i<10;i++)
{
dp[0][i] = 1;
}
for(int i=1;i<n;i++)
{
dp[i][0] = dp[i-1][0]+dp[i-1][8];
dp[i][1] = dp[i-1][1]+dp[i-1][2]+dp[i-1][4];
dp[i][2] = dp[i-1][2]+dp[i-1][3]+dp[i-1][1]+dp[i-1][5];
dp[i][3] = dp[i-1][2]+dp[i-1][6]+dp[i-1][3];
dp[i][4] = dp[i-1][1]+dp[i-1][5]+dp[i-1][7]+dp[i-1][4];
dp[i][5] = dp[i-1][2]+dp[i-1][4]+dp[i-1][6]+dp[i-1][8]+dp[i-1][5];
dp[i][6] = dp[i-1][3]+dp[i-1][5]+dp[i-1][6]+dp[i-1][9];
dp[i][7] = dp[i-1][4]+dp[i-1][7]+dp[i-1][8];
dp[i][8] = dp[i-1][5]+dp[i-1][7]+dp[i-1][8]+dp[i-1][0]+dp[i-1][9];
dp[i][9] = dp[i-1][9]+dp[i-1][8]+dp[i-1][6];
}
long sum = 0;
for(int i=0;i<10;i++)
{
sum = sum+dp[n-1][i];
}
return sum;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/June/15-6-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(n)
2 changes: 2 additions & 0 deletions LeetCode/June/15-6-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n*logn)
Space complexity - O(n)
35 changes: 35 additions & 0 deletions LeetCode/June/15-6-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class T
{
public int pro;
public int cap;
public T(int pro, int cap)
{
this.pro = pro;
this.cap = cap;
}
}

class Solution
{
public int findMaximizedCapital(int k, int W, int[] Profits, int[] Capital)
{
Queue<T> minHeap = new PriorityQueue<>((a, b) -> a.cap - b.cap);
Queue<T> maxHeap = new PriorityQueue<>((a, b) -> b.pro - a.pro);

for (int i = 0; i < Capital.length; ++i)
minHeap.offer(new T(Profits[i], Capital[i]));

while (k-- > 0)
{
while (!minHeap.isEmpty() && minHeap.peek().cap <= W)
maxHeap.offer(minHeap.poll());

if (maxHeap.isEmpty())
break;

W += maxHeap.poll().pro;
}

return W;
}
}

0 comments on commit a30d802

Please sign in to comment.