Video courses for company/skill based Preparation
Purchase mock tests for company/skill building
Cognizant GenC Elevate Sample Coding Question 5
In this article, we will discuss about Coding Question with their solution in java. In this Question , we have to find maximum number of bulbs jasleen can collect , starting from any machine and collecting from every consecutive machine until shre reaches the last machine she wants to collect from.
Jasleen has bought a new bulb factory. The factory has a single file of machines, numbered from 1 to N. Each machine has a certain number of fully prepared bulbs.
Jasleen has a rule she wants to follow. She wants to collect an equal amount of bulb from
each machine from which she collects bulbs.
Jasleen can start collecting bulb from any machine, but once she starts collecting, she collects
from every consecutive machine until she reaches the last machine she wants to collect from. Find the maximum number of bulbs she can collect.
Input1: N, the number of machines
Input2: An array of N elements (a1,a2 a3……aN], denoting the number of fully prepared bulbs in each machine of the factory.
An integer output denoting the maximum number of bulbs that Allie can collect.
public class Main
public static void main (Stringargs)
Scanner sc = new Scanner (System.in);
int n = sc.nextInt ();
int a = new int[n];
for (int i = 0; i < n; i++)
a[i] = sc.nextInt ();
ArrayList < Integer > a1 = new ArrayList <> ();
for (int i = a.length - 1; i >= 0; i--)
int x = 0;
x = a[i] * (a.length - i);
for (int i = 0; i < a1.size (); i++)
if (a1.get (a1.size () - 1 - i) >= a1.get (i))
System.out.println (a1.get (a1.size () - 1 - i));