Infosys 24th April All Slots Answers LIVE Updates in 5 Seconds Keep Refreshing

Infosys 24th April All Slots Answers LIVE Updates in 5 Seconds Keep Refreshing


1)Python 3

Special number after aurgument Code




8)A lot of sum Code Python

8)A lot of sum Code Python

3)Array
Java

  • import java.util.Arrays;

  • public class GFG {
  •     public static void main(String[] args) {

  •         int max = 1000000;
  •         int[] facs = new int[max];

  •         for (int i = 2; i < max; ++i) {
  •             for (int j = i; j < max; j += i) {
  •                 facs[j]++;
  •             }
  •         }

  •         // System.out.println(Arrays.toString(facs));
  •         int count = 0;
  •         for (int i = 0; i < max; ++i)
  •             if (facs[i] == 7)// 1 is a factor of all number so check for count 7
  •             {

  •                 if (primeFactors(i) == 2 + 1) {
  •                     System.out.println("YESSSSSSS");
  •                     break;
  •                 }
  •             }

  •         System.out.println(count);
  •     }

  •     static int primeFactors(int n) {
  •         // Print the number of 2s that divide n
  •         while (n % 2 == 0) {

  •             n /= 2;
  •         }
  •         // n must be odd at this point. So we can
  •         // skip one element (Note i = i +2)
  •         for (int i = 3; i <= Math.sqrt(n); i += 2) {
  •             // While i divides n, print i and divide n
  •             while (n % i == 0) {

  •                 n /= i;
  •             }
  •         }

  •         return n;
  •     }
  • }

4)Delete Edge to minimize subtree sum difference 
C++

  • #include <bits/stdc++.h> 
  • using namespace std; 
  •   
  • /* DFS method to traverse through edges, 
  • calculating subtree sum at each node and 
  • updating the difference between subtrees */
  • void dfs(int u, int parent, int totalSum, 
  •         vector<int> edge[], int subtree[], int& res) 
  •     int sum = subtree[u]; 
  •   
  •     /* loop for all neighbors except parent and 
  •         aggregate sum over all subtrees */
  •     for (int i = 0; i < edge[u].size(); i++) 
  •     { 
  •         int v = edge[u][i]; 
  •         if (v != parent) 
  •         { 
  •             dfs(v, u, totalSum, edge, subtree, res); 
  •             sum += subtree[v]; 
  •         } 
  •     } 
  •   
  •     // store sum in current node's subtree index 
  •     subtree[u] = sum; 
  •   
  •     /* at one side subtree sum is 'sum' and other side 
  •         subtree sum is 'totalSum - sum' so their difference 
  •         will be totalSum - 2*sum, by which we'll update 
  •         res */
  •     if (u != 0 && abs(totalSum - 2*sum) < res) 
  •         res = abs(totalSum - 2*sum); 
  •   
  • // Method returns minimum subtree sum difference 
  • int getMinSubtreeSumDifference(int vertex[], 
  •                     int edges[][2], int N) 
  •     int totalSum = 0; 
  •     int subtree[N]; 
  •   
  •     // Calculating total sum of tree and initializing 
  •     // subtree sum's by vertex values 
  •     for (int i = 0; i < N; i++) 
  •     { 
  •         subtree[i] = vertex[i]; 
  •         totalSum += vertex[i]; 
  •     } 
  •   
  •     // filling edge data structure 
  •     vector<int> edge[N]; 
  •     for (int i = 0; i < N - 1; i++) 
  •     { 
  •         edge[edges[i][0]].push_back(edges[i][1]); 
  •         edge[edges[i][1]].push_back(edges[i][0]); 
  •     } 
  •   
  •     int res = INT_MAX; 
  •   
  •     // calling DFS method at node 0, with parent as -1 
  •     dfs(0, -1, totalSum, edge, subtree, res); 
  •     return res; 
  •   
  • // Driver code to test above methods 
  • int main() 
  •     int vertex[] = {4, 2, 1, 6, 3, 5, 2}; 
  •     int edges[][2] = {{0, 1}, {0, 2}, {0, 3}, 
  •                     {2, 4}, {2, 5}, {3, 6}}; 
  •     int N = sizeof(vertex) / sizeof(vertex[0]); 
  •   
  •     cout << getMinSubtreeSumDifference(vertex, edges, N); 
  •     return 0; 

5) Make palindrome code 
python


  • def isPalindrome(Str):
  •  

  •     Len = len(Str)
  •  


  •     if (Len == 1):

  •         return True
  •  

  •     

  •     ptr1 = 0
  •  

  •    

  •     ptr2 = Len - 1
  •  

  •     while (ptr2 > ptr1):
  •  

  •         if (Str[ptr1] != Str[ptr2]):

  •             return False

  •         ptr1 += 1

  •         ptr2 -= 1
  •  

  •     return True
  •  

  • def noOfAppends(s):
  •  

  •     if (isPalindrome(s)):

  •         return 0
  •  

  •     

  •     del s[0]
  •  
  •     return 1 + noOfAppends(s)
  •  
  • //allcoding1

  • se = "abede"

  • s = [i for i in se]
  • print(noOfAppends(s))


6) Rectangular formation code in Python

Rectangular formation code in Python

7) Number pairs

Number pairs



8. Chair Game Code

Chair Game Code



9) LIS Problem

LIS Problem

10. Prifix XOR code in Java

  • // Java program to find the XOR of
  • // all elements in the array
  • class GFG {
  •      
  •     // Function to find the XOR of
  •     // all elements in the array
  •     static int xorOfArray(int arr[], int n)
  •     {
  •         // Resultant variable
  •         int xor_arr = 0;
  •      
  •         // Iterating through every element in
  •         // the array
  •         for (int i = 0; i < n; i++) {
  •      
  •             // Find XOR with the result
  •             xor_arr = xor_arr ^ arr[i];
  •         }
  •      
  •         // Return the XOR
  •         return xor_arr;
  •     }
  •      
  •     // Driver Code
  •     public static void main (String[] args)
  •     {
  •      
  •         int arr[] = { 3, 9, 12, 13, 15 };
  •         int n = arr.length;
  •      
  •         // allcoding1
  •         System.out.println(xorOfArray(arr, n));
  •  
  •     }
}


11. Python Computer game Code

Python Computer game Code

12. Beautiful Binary String HackerRank Solution in C++

  • #include <map>
  • #include <set>
  • #include <list>
  • #include <cmath>
  • #include <ctime>
  • #include <deque>
  • #include <queue>
  • #include <stack>
  • #include <string>
  • #include <bitset>
  • #include <cstdio>
  • #include <limits>
  • #include <vector>
  • #include <climits>
  • #include <cstring>
  • #include <cstdlib>
  • #include <fstream>
  • #include <numeric>
  • #include <sstream>
  • #include <iostream>
  • #include <algorithm>
  • #include <unordered_map>
  • using namespace std;
  • char B[105];
  • int main(){
  •     int n;
  •     int ans=0;
  •     scanf("%d", &n);
  •     scanf("%s", B);
  •     for(int i=2; B[i]; i++){
  •         if(B[i-2] == '0' && B[i-1] == '1' && B[i] == '0') B[i] = '1', ans++;
  •     }
  •     printf("%d", ans);
  •     return 0;
  • }

Available
  1. Xor operation

  2. Rectangular operation

  3. Replace elements



  4. Xor operation

  5. Rectangular operation

  6. Replace elements

  7.  Xor operation

  8. Rectangular operation

  9. Replace elements

  10. Available
  11. Xor operation

  12. Rectangular operation

  13. Replace elements



  14. Xor operation

  15. Rectangular operation

  16. Replace elements


  17.  Xor operation

  18. Rectangular operation

  19. Replace elements


  20. Available
  21. Xor operation

  22. Rectangular operation

  23. Replace elements

  24. Xor operation

  25. Rectangular operation

  26. Replace elements

  27.  Xor operation

  28. Rectangular operation

  29. Replace elements

  30. Filling seats code

  31. Maximum sum of minimum code

  32. Sort the array code


12. Replace element code

Replace element code

______________________________






_______________________




______________________

Positive sum segment code in python

Positive sum segment code in python

Gcd code in java 8

Gcd code in java 8

Maximum difference code in python 2

Maximum difference code in python 2

Buddy with factor

Buddy with factor

Buddy with factor

A lots of sum code in python

A lots of sum code in python

Perfect subsequnce

Perfect subsequnce

Maximize the multiplication

Maximize the multiplication

Maximize the multiplication

Make palindrome code in python

  • def isPalindrome(Str):
  •  

  •     Len = len(Str)
  •  


  •     if (Len == 1):

  •         return True
  •  

  •     

  •     ptr1 = 0
  •  

  •    

  •     ptr2 = Len - 1
  •  

  •     while (ptr2 > ptr1):
  •  

  •         if (Str[ptr1] != Str[ptr2]):

  •             return False

  •         ptr1 += 1

  •         ptr2 -= 1
  •  

  •     return True
  •  


  • def noOfAppends(s):
  •  

  •     if (isPalindrome(s)):

  •         return 0
  •  

  •     

  •     del s[0]
  •  

  •     return 1 + noOfAppends(s)
  •  


  • se = "abede"

  • s = [i for i in se]
  • print(noOfAppends(s))

String Updation code

String Updation code

1.Happy hour code 

2.Prime with square

3.Removing a character 

1.Remove the balls

2.NHT

3.Removing a character

Infosys Specialist programer exam

Msps code
  1. // Online C++ compiler to run C++ program online
  2. #include <bits/stdc++.h>
  3. using namespace std;

  4. int func(int n){
  5.       int cnt=0;
  6.     for (int i=1; i<=sqrt(n); i++)
  7.     {
  8.         if (n%i == 0)
  9.         {
  10.             if (n/i == i)
  11.                 cnt++;
  12.             else
  13.                 cnt+=2;
  14.         }
  15.     }
  16.     return cnt;
  17. }

  18. int calcSum(int arr[], int n, int k)
  19. {
  20.     int sum = 0;
  21.     for (int i = 0; i < k; i++)
  22.         sum += arr[i];
  23.     int mx=func(sum);
  24.  
  25.     for (int i = k; i < n; i++) {
  26.         sum = (sum - arr[i - k]) + arr[i];
  27.         mx=max(mx,func(sum));
  28.     }
  29.     return mx;
  30. }



  31. int main() {
  32.     // Write C++ code here
  33.     int n,k;
  34.     cin>>n>>k;
  35.     int arr[n];
  36.     for(int i=0;i<n;i++)
  37.         cin>>arr[i];
  38.     
  39.     cout<<calcSum(arr, n, k)*k;
  40.   

  41.     return 0;
  42. }
rectangle code in python                         

  • def rec(a):
  •     b=[]
  •     for i in range(len(a)):
  •         for  j in range(len(a)):
  •             if a[i]!=a[j] and i!=j:
  •                 area=a[i]*a[j]
  •                 b.append(area)
  •     return max(b)
  • if name== "main" :
  •     n=int(input())
  •     A=[]
  •     for i in range(n):
  •         A.append(int(input()))
  •     print(rec(A))
⚡️ Sequences concatenation code ⚡️

  • ArrayList<Integer> ar = new ArrayList<Integer>();
  • ArrayList<Integer> ar1 = new ArrayList<Integer>();
  • ArrayList<Integer> arr2= new ArrayList<Integer>();
  • ArrayList<Integer> sza= new ArrayList<Integer>();
  • ArrayList<Integer> p_n= new ArrayList<Integer>();

  • Scanner sc = new Scanner(System.in);

  • int a_size= sc.nextInt();
  • int m_size=sc.nextInt();
  • int[] a = new int[a_size];
  • for(int i=0;i<a_size;i++){
  • a[i]=sc.nextInt();
  • arr2.add(a[i]);
  • }
  • int[] p = new int[m_size];
  • for(int i=0;i<m_size;i++){
  • p[i]=sc.nextInt();
  • p_n.add(p[i]);
  • }
  • int[] sz=new int[m_size];
  • for(int i=0;i<m_size;i++){
  • sz[i]=sc.nextInt();
  • sza.add(sz[i]);
  • }

  • for(int i=0;i<a_size;i++)
  • {
  • for(int j=0;j<m_size;j++)
  • {
  • if(a[i]==p[j])
  • {
  • ar.add(p[j]);
  • }
  • }
  • }
  •    int [] fr = new int [ar.size()];  
  •         int visited = -1;  
  •         for(int i = 0; i < ar.size(); i++){  
  •             int count = 1;  
  •             for(int j = i+1; j < ar.size(); j++){  
  •                 if(ar.get(i).equals(ar.get(j))){  
  •                     count++;  
  •                     fr[j] = visited;  
  •                 }  
  •             }  
  •             if(fr[i] != visited)  
  •                 fr[i] = count;  
  •         }  
  •  
  •         for(int i = 0; i < fr.length; i++){  
  •             if(fr[i] != visited)  
  •                ar1.add(fr[i]);
  •         }  
  •        ArrayList<Integer> pnew = new ArrayList<Integer>();
  •        for(int l=0;l<sz.length;l++)
  •        {
  •     for(int h=0;h<sza.get(l);h++)
  •     {
  •     pnew.add(p_n.get(l));
  •     }
  •        }
  •        int count=0;
  •        for(int i = 0; i < pnew.size(); i++)
  •        {
⚡️ Sequences concatenation code ⚡️
_______________________


  • def XorOfArray(n):
  •     x =0;
  •     for i in range(len(n)):
  •         x = x ^ n[i]
  •     return x

  • def NoOfFactors(n):
  •     numcount = 0
  •     for i in range(2,n + 1):
  •         if n % i == 0:
  •             count = 1
  •             for j in range(2,(i//2 + 1)):
  •                 if(i % j == 0):
  •                     count = 0
  •                     break
  •             if(count == 1):
  •                 numcount+=1
  •     return numcount


  • def MaxScore(n, k, A):
  •     maxs = 0
  •     for i in range((n - k)+ 1):
  •         subarr = []
  •         for j in range(i, i+k):
  •             subarr.append(A[j])
  •         xor = XorOfArray(subarr)
  •         if xor != 0:
  •             nofacts = NoOfFactors(xor)
  •             tempMax = nofacts * k
  •             if maxs < tempMax:
  •                 maxs = tempMax
  •     return maxs




  • n = int(input())
  • k = int(input())
  • A = []
  • for i in range(n):
  •     A.append(int(input()))
  • maxScr = MaxScore(n, k, A)
  • print(maxScr)
__________________________

NGD code solution

  • #include<bits/stdc++.h>
  • using namespace std;
  • typedef long long int ll;
  • int main()
  • {
  •     map<int,int> s;
  •     s.insert({0,0});
  •     for(int i=1;i<=10000;i++)
  •         s.insert({i*i,1});
  •     int n;
  •     cin>>n;
  •     int a[n];int ans=0;
  •     for(int i=0;i<n;i++){
  •         cin>>a[i];
  •         int t=a[i]/2;
  •         for(int j=1;j*j<=t;j++){
  •             if(s[a[i]-j*j]==1)
  •                 ans++;
  •         }
  •     }
  •     cout<<ans<<endl;
  • }
_______________

⚡️ Prime With Squares Code ⚡️
Language : Python 

Prime With Squares Code

____________________________

Equal array 
Language - c++
Infosys dse and sp

Equal array  Language - c++ Infosys dse and sp

____________________

Knapsack code done ✅
Language c++
Infosys dse sp

Knapsack code done ✅ Language c++ Infosys dse sp


_______________________

Equal array code

Equal array code

LVP code in python

LVP code in python

____________________

Good Pairs 

Stream : Python 2

Good Pairs   Stream : Python 2

⚡️ MSSS code in python ⚡️

⚡️MSSS code in python⚡️

_____________


⚡️Beautiful binary string code⚡️

  • #include <map>
  • #include <set>
  • #include <list>
  • #include <cmath>
  • #include <ctime>
  • #include <deque>
  • #include <queue>
  • #include <stack>
  • #include <string>
  • #include <bitset>
  • #include <cstdio>
  • #include <limits>
  • #include <vector>
  • #include <climits>
  • #include <cstring>
  • #include <cstdlib>
  • #include <fstream>
  • #include <numeric>
  • #include <sstream>
  • #include <iostream>
  • #include <algorithm>
  • #include <unordered_map>
  • using namespace std;
  • char B[105];
  • int main(){
  •     int n;
  •     int ans=0;
  •     scanf("%d", &n);
  •     scanf("%s", B);
  •     for(int i=2; B[i]; i++){
  •         if(B[i-2] == '0' && B[i-1] == '1' && B[i] == '0') B[i] = '1', ans++;
  •     }
  •     printf("%d", ans);
  •     return 0;
  • }
⚡️ Prime with square ⚡️

⚡️Prime with square⚡️

⚡️GCD MAXIMIZATION code in java⚡️

⚡️GCD MAXIMIZATION code in java⚡️

⚡️Oblivious code ⚡️ Stream : JAVA 8

⚡️Oblivious code ⚡️ Stream : JAVA 8

Happy hour code in python

Happy hour code in python

Prime with Square

Prime with Square
Prime with Square

Python bitwise operations

Python bitwise operations


👉👉 Remove the character 
Stream : C++ 
  • int res = 0,i = 0;
  •  bool removed,valid;
  •  for(string& str : t)
  •  {
  •   i = 0; removed = false; valid = true;
  •   for(int j=0;j<(n-1);i++,j++)
  •   {
  •    if(s[i] == str[j]){continue;}
  •    if(removed){valid = false; break;}
  •    removed = true; j--;
  •   }
  •   if(valid){res++;}
  •  }
  •  return res;
MNC CODE IN C++

MNC CODE IN C++

Share and support

⚡️Remove the characters in C++⚡️

  • int res = 0,i = 0;
  •  bool removed,valid;
  •  for(string& str : t)
  •  {
  •   i = 0; removed = false; valid = true;
  •   for(int j=0;j<(n-1);i++,j++)
  •   {
  •    if(s[i] == str[j]){continue;}
  •    if(removed){valid = false; break;}
  •    removed = true; j--;
  •   }
  •   if(valid){res++;}
  •  }
  •  return res;



Comments

  1. String updation code
    Arranging numbers code

    ReplyDelete
  2. Happy hour
    Rectangle
    Fibonacci strings

    ReplyDelete
  3. Subsequence and distance
    I hate max
    Code pls

    ReplyDelete
  4. Organise the class
    Knapsack again
    Company hierarchy

    ReplyDelete
  5. String updation code
    Arranging numbers code
    Most beautiful segment codes

    ReplyDelete
  6. Sort the array and nkp code please

    ReplyDelete
  7. Send most beautiful segment
    Filling seats
    Number ways
    Code please please it's a request

    ReplyDelete
  8. Subsequence and ditmstance code plss

    ReplyDelete
  9. Special subsequence
    Swap game
    Coin distribution

    ReplyDelete
  10. Remove the ball
    A bit hard problem
    NHT

    ReplyDelete
  11. Bitwise operations and LCSS code please

    ReplyDelete
  12. Sort the array is not there please upload

    ReplyDelete
  13. Subsequence and distance
    I hate max code plsss

    ReplyDelete
  14. Remainder one
    Max expertise
    MNC
    Code please

    ReplyDelete
  15. Remove the balls
    Happy hour
    Amazing sequence

    ReplyDelete
  16. Rectangle
    Sum of segment
    A bit hard problem

    ReplyDelete
  17. Subsequence and distance
    I hate max code plss

    ReplyDelete
  18. Prime with squares
    Maher needs to clean
    Or function

    ReplyDelete
  19. Increasing sequence
    Swap game
    Replace elements

    ReplyDelete
  20. GCD maximization code plzzzz plzzz

    ReplyDelete
  21. Fourlets count
    MNC code plzzzzzzzzzzzzzz


    Fourlets count
    MNC code plzzzzzzzzzzzzzz

    ReplyDelete
  22. Sir plz MSSS code
    And maximum possible score

    ReplyDelete
  23. Arranging numbers code please

    ReplyDelete

Post a Comment