Skip to content

Commit

Permalink
Added codes for 12 Feb
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Feb 12, 2024
1 parent 8e7ab0c commit 53d0ab8
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
55 changes: 55 additions & 0 deletions GeeksForGeeks/February/12-2-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//{ Driver Code Starts
//Initial Template for Java

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

class GFG{
public static void main(String args[])throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(in.readLine());
while(t-- > 0){
int N = Integer.parseInt(in.readLine());

Solution ob = new Solution();
System.out.println(ob.sequence(N));
}
}
}
// } Driver Code Ends


//User function Template for Java

class Solution{
static long sequence(int n)
{
long mod=1000000007;
return func(n,1,0,1)%mod;
}

static long func(int n, int iterations, long sum , int start)
{
if(n==0)
{
return sum;
}

int it = iterations;

long pro=1, mod=1000000007;

while(it>0)
{
pro=pro*start;
pro%=mod;
start++;
it--;
}

sum+=pro;

return func(n-1,iterations+1,sum,start);
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/February/12-2-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n^2)
Space complexity - O(1)
2 changes: 2 additions & 0 deletions LeetCode/February/12-2-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(1)
18 changes: 18 additions & 0 deletions LeetCode/February/12-2-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution
{
public int majorityElement(int[] nums)
{
Integer ans = null;
int count = 0;

for (int num : nums)
{
if (count == 0)
ans = num;

count += num == ans ? 1 : -1;
}

return ans;
}
}

0 comments on commit 53d0ab8

Please sign in to comment.