Posts

Recursive Sequence Geeks For Geeks Problem Of The Day 12-02-2024

Problem Link: https://www.geeksforgeeks.org/problems/recursive-sequence1611/1 Code: class Solution{     static long sequence(int n){                 long sum=0;         int pointer=0;                  int mod=1000000007;         int pointer2=1;                  for(int i=1;i<n+1;i++){            pointer=i;            long val=1;            int mul=pointer2;            for(int j=0;j<pointer;j++){                val=(val*mul)%mod;                mul++;            }            pointer2=mul;            sum=(sum+val)%mod; ...

Java Date And Time HackerRank

CODE:   public   static  String findDay( int  month,  int  day,  int  year) {         String finalday= " " ;          try {             String d1= day+ "/" +month+ "/" +year;             SimpleDateFormat sdf= new  SimpleDateFormat( "dd/MM/yyyy" );             Date date1=sdf.parse(d1);             DateFormat format1= new  SimpleDateFormat( "EEEE" );            finalday=format1.format(date1);              // return finalday;      ...

Good Subtrees Problem Of The Day GFG

Problem Link: https://practice.geeksforgeeks.org/problems/df12afc57250e7f6fc101aa9c272343184fe9859/1 Solution : class Solution {     // static LinkedHashSet<Integer> set1=new LinkedHashSet<Integer>();     // static LinkedHashSet<Integer> set2=new LinkedHashSet<Integer>();         public static LinkedHashSet<Integer> fun(Node root, int k,int[] count){         if(root==null){             return new LinkedHashSet<Integer>();         }         else{             LinkedHashSet<Integer> set1=fun(root.left,k,count);             LinkedHashSet<Integer> set2=fun(root.right,k,count);             set1.addAll(set2);             set1.add(root.data);                 ...

Make array elements unique. Geeks For Geeks

 Problem Link: https://practice.geeksforgeeks.org/problems/6e63df6d2ebdf6408a9b364128bb1123b5b13450/1 It is also the problem of the day for 11-01-2023 Solution: class Solution {     public long minIncrements(int[] arr, int n) {        long count=0;        Arrays.sort(arr);     //   for(int a:arr){     //       System.out.print(a+" ");     //   }        HashMap<Integer,Integer>map=new HashMap<Integer,Integer>();       int index=1;       for(int a:arr){           if(index<a){               index=a;               index++;               map.put(a,1);               //condition1           }       ...

3 Divisors Geeks For Geeks

Problem Link: https://practice.geeksforgeeks.org/problems/3-divisors3942/1 It is also the problem of the day for 8-12-2022 Solution: //{ Driver Code Starts //Initial Template for Java import java.io.*; import java. util.*; class GFG {     public static void main(String args[])throws IOException     {         Scanner sc = new Scanner(System.in);         int t = sc.nextInt();         while(t-->0){             int q = sc.nextInt();             ArrayList<Long> query = new ArrayList<>();             for(int i=0;i<q;i++){                 query.add(sc.nextLong());             }             Solution ob = new Solution();                          ...

Find Players With Zero or One Losses LeetCode

Problem Link: https://leetcode.com/problems/find-players-with-zero-or-one-losses/description/ Solution Link: class Solution {     public List < List < Integer >> findWinners ( int [][] matches ) {         TreeMap <Integer,Integer>map1= new TreeMap < Integer , Integer >();         TreeMap <Integer,Integer>map2= new TreeMap < Integer , Integer >();         for ( int i = 0 ;i< matches . length ;i++){             int a =matches[i][ 0 ];                         if ( map1 . containsKey (a)){                 map1 . put (a, map1 . get (a)+ 1 );             }             else {                 map1 . put (a, 1 );             }...

LCM Triplet Geeks For Geeks

Problem Link: https://practice.geeksforgeeks.org/problems/lcm-triplet1501/1 (It is also the problem of the day for 20-11-2022.) Solution: class Solution {     long lcmTriplets(long N) {         if(N<=2){             return N;         }         else if((N&1)==0){             if(N%3==0){                 N--;                 return N*(N-1)*(N-2);             }             return N*(N-1)*(N-3);         }         return N*(N-1)*(N-2);     } } Time Complexity: O(log n)[GFG Time:2.22] Space Complexity:O(1) Auxiliary Space:O(1) Total Test Cases: 1000105 Approach Used: Here we observe carefully. Then we notice one thing we need to return the multiplication of three numbers a...