• Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
CODE OF GEEKS

We at CODE OF GEEKS, aim at providing best and quality content for our users at no extra cost.

    • Study Materials – Company wise
      • Infosys Archive
      • Accenture Archive
      • AMCAT Archive
      • Capgemini Archive
      • Cisco Archive
      • CoCubes Archive
      • Cognizant(CTS) Archive
      • Dell Archive
      • Deloitte Archive
      • DXC Archive
      • Goldman Sachs Archive
      • Hexaware Technologies Archive
      • LTI Archive
      • MindTree Archive
      • TCS Archive
      • Virtusa Archive
      • Wipro Archive
    • Interview Preparation – E Books
      • C Interview Questions
      • Data Structures Interview Questions
      • DBMS Interview Questions
      • HR Interview Questions
      • Java Interview Questions
      • Operating System Interview Questions
      • Python Interview Questions
      • SQL Query Interview Questions
    • Programming
      • C Programming MCQs
      • C Code Snippets – Output Questions
      • Python Code Snippets – Output Questions
    • Aptitude
      • Verbal Ability for Placements
      • Quant for Placements
    • Register
    • Login
  • [email protected]
  • ..
Login / Register
Apply Now
CODE OF GEEKS
CODE OF GEEKS
  • Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
0

Cart

Great Sum

  • January 29, 2020
  • CODE OF GEEKS
  • 2

Given a special set of numbers and a special sum. Find all those combinations from the given set, equaling the given sum

Input : 

First Input : Set of numbers

Second Input : Special Sum

Output : 

Combinations satisfying criteria

Sample Testcases :

I/P 1:

-1, 1, 0, 0, 2, -2

0

O/P 1

3


Explanation : Following combinations are satisfying (-1,1,2,-2), (0, 0, 1, -1), (0, 0, -2, 2)

Note : Make combinations with 4 integers only.

Solution :

import itertools
l=list(map(int,input().split(",")))
s=int(input())
res=list(itertools.combinations(l,4))
c=0
for i in res:
    u=sum(i)
    if u == s:
       c+=1
print(c)


Tags: infosys last year handson problemsinfytqinfytq examinfytq handson problems of last yearinfytq handson questionsinfytq last year problemsinfytq last year questionsLast year questions Infytqmatrix problem for infytqmatrix problem infytqprepare infytq question
  • Previous Matrix Number Game
  • Next Matrix Sum

2 comments on “Great Sum”

  1. Ashutosh Tripathi Ashutosh Tripathi says:
    April 16, 2021 at 4:24 pm

    /*package whatever //do not write package name here */

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

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

    String sstr=”-1,1,0,0,2,-2″;
    int sum=0;
    String[] str= sstr.split(“,”);
    int[] arr=new int[str.length];
    for(int k=0;k<str.length;k++)
    arr[k]=Integer.parseInt(str[k]);

    int count=0;
    for(int i=0;i<arr.length;i++){
    for(int j=i+1;jsum)
    break;

    }

    }

    System.out.println(count);

    }

    }

    Reply
  2. Deepanshi Srivastava says:
    April 17, 2021 at 2:52 pm

    import java. io.*;
    import java. util.*;
    import java. lang.*;
    public class Main
    {
    public static void main(String args[])
    {
    Scanner Sc = new Scanner(System.in);
    String t = Sc.nextLine();
    String k[] = t.split(“,”);
    //System.out.println(k.length);
    int c=0;
    int sum = Sc.nextInt();
    int i,j,kk,l;
    for(i=0;i<k.length-3;i++)
    {
    for(j=i+1;j<k.length-2;j++)
    {
    for(kk=j+1;kk<k.length-1;kk++)
    {
    for(l=kk+1;l<k.length;l++)

    { int r = Integer.parseInt(k[i]);
    int r1 = Integer.parseInt(k[j]);
    int r2 = Integer.parseInt(k[kk]);
    int r3 = Integer.parseInt(k[l]);
    //System.out.println((r+r1+r2+r3));
    if((r+r1+r2+r3)==sum)
    c++;

    }}}}
    System.out.println(c);}
    }

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CODE OF GEEKS

Subscribe to Newsletter

CODE OF GEEKS

Learn | Code | Achieve

Reach us

[email protected]
We at CODE OF GEEKS, aim at providing quality content to our users at no cost.
CODE OF GEEKS

Important Pages

About us
Advertise
Privacy Policy
Terms and Conditions

Placements – Study Materials

TCS NQT     Wipro     CapGemini
Accenture     MindTree     CTS
DXC     Hexaware Technologies     AMCAT
CoCubes     Goldman Sachs     Dell
Cisco     Deloitte     Virtusa     LTI     Infosys   

Courses

  • Mail Us
  • Login/Register

Recent Posts

What is Cloud Computing | Cloud Computing Applications | Cloud Development Models| SaaS vs PaaS vs IaaS
  • October 23, 2021
What is Amazon Web Services | AWS Regions & AZs | Different AWS Services
  • October 19, 2021

Copyright 2021 CODE OF GEEKS. All Rights Reserved.

  • →