• 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

Marathon Winner

  • March 19, 2020
  • CODE OF GEEKS
  • 5


Race is generally organized by distance but this race will be organized by time. In order to predict the winner we will check every 2 seconds.
Let’s say total race time is 7 seconds we will check for (7-1) seconds.
For 7 sec : we will check who is leading at 2 sec, 4 sec, and 6 sec.
Participant who is leading more number of times is winner from prediction perspective.
Now our task is to predict a winner in this marathon.

Note :

  1. At particular time let say at 4th second, top two (top N, in general) participants are at same distance, then in this case both are leading we’ll increase count for both(all N).
  2. And after calculating at all time slices, if the number of times someone is leading, is same for two or more participants, then one who come first in input sequence will be the winner.

Ex. If participant 2 and 3 are both leading with same number, participant 2 will be the winner.

Constraints

1 <= T <= 100
1 <= N <= 100



Input Format

First line contains a single integer N denoting the number of participants.
Second line contains a single integer T denoting the total time in seconds of this Marathon.
Next N lines (for each participant) are as follows :

We have T+1 integers seperated by space.
First T integers are as follows :
ith integer denotes number of steps taken by the participant at the i-th second.
T+1st integer denotes the distance (in meters) of each step.

Output

Index of Marathon winner, where index starts with 1.

Test Case

Input

3
8
2 2 4 3 5 2 6 2 3
3 5 7 4 3 9 3 2 2
1 2 4 2 7 5 3 2 4

Output

2



Tags: codevitatcstcs codevita 2019 coding questionstcs codevita 2020tcs codevita coding questionstcs codevita last year coding questions 2019tcs codevita questions 2019tcscodevita
  • Previous Holes and Balls
  • Next Roman Iteration

5 comments on “Marathon Winner”

  1. Prashant says:
    April 12, 2020 at 3:05 pm

    import java.io.*;
    import java.util.Arrays;
    class Main
    {
    public static void main(String[] args)throws IOException
    {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    //———————————————————————-
    int participants=Integer.parseInt(br.readLine()); //No. of players
    int seconds=Integer.parseInt(br.readLine()); // no. of seconds
    //———————————————————————-

    int record[][]=new int[participants][seconds+1];
    /*
    why seconds+1?
    ans: cuase last column is for distance
    */
    //———————————————————————-
    int lead[]=new int[participants];// count
    //———————————————————————-
    Arrays.fill(lead,0);// filled 0’s to count

    // preprocessing and input
    for(int i=0;i<participants;i++)
    {
    String input=br.readLine(); input.trim();
    input=input.replaceAll("\\s+","");
    if(input.length()!=seconds+1)System.exit(0);
    for(int j=0;j<input.length();j++){
    record[i][j]=Character.getNumericValue(input.charAt(j));
    }
    }

    // main logic
    for(int i=0;i<participants;i++){
    // remember last digit is the length of a step
    int length=record[i][seconds];
    // finding cummilative sum
    for(int j=0;j<seconds-1;j++){
    if(j!=0){
    record[i][j]=record[i][j-1]+(record[i][j]*length);
    }
    else{
    record[i][j]= (record[i][j]*length);
    }
    }

    }
    //———————————————————————

    int start=(seconds%2==0)?0:1;
    int max=0;

    for(int i=start;i<=seconds-2;i+=2)
    {
    System.out.println("ROUND NUM. "+ i+"————————–");
    System.out.println(" PARTICIPANT NO. OF LEADS ");
    for(int j=0;j=max)max=record[j][i];
    }
    for(int k=0;k<participants;k++){

    if(record[k][i]==max)lead[k]++;
    System.out.println("CHECK LEAD "+k+" "+lead[k]);
    }
    System.out.println("MAX CHECK "+ max );
    max=0;
    }

    max=0;

    for(int i=0;i=max)max=lead[i];
    }

    for(int i=0;i<participants;i++){
    if(lead[i]==max){
    System.out.println(i+1);
    break;
    }
    }

    }
    }

    Reply
  2. amt kumar says:
    June 11, 2020 at 9:23 am

    #include
    #include
    #include
    using namespace std;
    int max_of_sublist(int sum_list[])
    {
    int k=INT_MIN;
    int z=sizeof(sum_list)/sizeof(sum_list[0]);
    for(int i=0;i<z;i++)
    {
    if(k<sum_list[i])
    k=sum_list[i];
    }
    return k;
    }
    int who_win(int winer[])
    {

    int k;
    int m=winer[0];
    int z=sizeof(winer)/sizeof(winer[0]);
    for(int i=0;i<z;i++)
    {
    if(m>t;
    int n;
    cin>>n;
    int step[t][n];
    for(int i=0;i<t;i++)
    for(int j=0;j>step[i][j];
    int winer[t];
    int sum_list[t]={0};
    for(int second=2;second<=n;second+2)
    {
    for(int pn=0;pn<t;pn++)
    {

    sum_list[pn]+=(step[pn][second-2]+step[pn][second-1])*step[pn][n];

    }
    int z;
    z=max_of_sublist(sum_list);
    for(int x=0;x<t;x++)
    {
    if(sum_list[x]==z)
    winer[x]+=1;
    }
    }
    cout<<who_win(winer)+1;

    return 0;
    }

    Reply
  3. Shrutik Gumate says:
    June 17, 2020 at 1:31 pm

    n=int(input())
    t=int(input())
    ply=[]
    for i in range(n):
    x=list(map(int,input().split()))
    y=x[-1]
    x=x[:-1]
    x[0]=x[0]*y
    for i in range(1,t):
    x[i] *= y
    x[i] += x[i-1]
    ply.append(x)
    if t%2==0:
    t -= 2
    else:
    t -= 1
    d={}
    for i in range(1,n+1):
    d[i] = 0
    for i in range(2,t+1,2):
    m = 0
    t1 = []
    for j in range(n):
    x = ply[j][i – 1]
    if m < x:
    m = x
    t1 = []
    t1.append(j+1)
    elif m == x:
    t1.append(j+1)
    for k in t1:
    d[k] += 1
    m = max(d.values())
    for i in d.keys():
    if d[i] == m:
    print(i)
    break;

    Reply
  4. pipaliya vishal pipaliya vishal says:
    June 23, 2020 at 8:55 am

    package project;
    import java.util.*;
    public class marathon {
    public static void main(String[] args){
    System.out.println(“vishal….”);
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    int T=sc.nextInt();
    int S[][]=new int[N][T+1];
    for(int i=0;i<N;i++)
    {
    for(int j=0;j<T;j++)
    {
    S[i][j]=sc.nextInt();
    }

    }
    int t[]=new int[N];
    int le[]=new int[N];
    for(int j=1;j<T-1;j=j+2)
    {
    for(int i=0;i<N;i++)
    {
    t[i]=S[i][j];
    le[i]=0;
    }
    int l=t[0],m=0;
    for(int k=0;kl)
    { l=t[k]; m=k; }
    }
    le[m]=le[m]+1;
    }
    int l=le[0],m=0;
    for(int k=0;kl)
    { l=le[k]; m=k; }
    }

    System.out.println(” ” +(m+1));
    }
    }

    Reply
  5. vishnu byreddi vishnu byreddi says:
    July 10, 2020 at 6:01 am

    #include
    int main()
    {
    int n,sec,km,a[10][10],i,j,k=2,b[10],l[10],m[10],r[10],max=0,f;
    printf(“enter no of racers”);
    scanf(“%d”,&n);
    printf(“enter no of seconds”);
    scanf(“%d”,&sec);
    for(i=0;i<n;i++)
    {
    printf("enter the values of %d racer",i+1);
    for(j=0;j<sec;j++)
    {
    scanf("%d",&a[i][j]);
    }
    printf("enter the speed of %d racer :",i+1);
    scanf("%d",&b[i]);
    }
    for(i=0;i<n;i++)
    {
    m[i]=0;
    r[i]=0;
    }
    while(k<=sec)
    {
    max=0;
    for(i=0;i<n;i++)
    {
    l[i]=((a[i][k-2])*b[i]+(a[i][k-1]*b[i]));
    m[i]=m[i]+l[i];
    }
    for(i=0;imax)
    {
    max=m[i];
    f=i;
    }
    }
    r[f]=r[f]+1;
    k=k+2;

    }
    max=0;
    f=0;
    for(i=0;imax)
    {
    max=r[i];
    f=i;
    }
    }
    printf(“\n%d racer is the winner”,f+1);
    }

    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

TCS Reasoning 2021
  • October 4, 2021
TCS Verbal 2021
  • October 4, 2021

Copyright 2021 CODE OF GEEKS. All Rights Reserved.

  • →