Posts

Showing posts from February, 2024

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;         }         return sum;     } } Solution Approach: Here we need to find out the sum of product of consecutive numbers up to a particular range. 1.In problem it is given that if i==2 then it means 2 consecutive numbers product and later on their product should be added in overall sum. Now the major thing is to identify that these 2 consecutive numbers will be what ie (1,2) or (2,3) or (3,4) so for that they have given condition that number which was used last fo

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;         }          catch (Exception e){             System.out.println(e);         }                 return  finalday.toUpperCase();                                }