We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I am solving this challenge in C#.I am getting stuck with the input, which is why I am unable to submit my code. Any help would be appreciated. Following is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ServiceLane
{
class Program
{
public class ServiceLane
{
long N;
long T;
int[] width;
public ServiceLane(long N, long T, int[] width)
{
this.N = N;
this.T = T;
this.width = width;
}
public int findLargestVehicle(long i, long j)
{
int entryWidth = width[i];
int exitWidth = width[j];
int largestVehicle = (entryWidth <= exitWidth) ? entryWidth : exitWidth;
if (largestVehicle > 1)
{
for (long segmentIndex = i + 1; segmentIndex < j && largestVehicle > 1; segmentIndex++)
{
if (largestVehicle > width[segmentIndex])
{
largestVehicle = width[segmentIndex];
}
}
}
return largestVehicle;
}
}
static void Main(string[] args)
{
long N =(long)Convert.ToDouble( Console.ReadLine());
long T = (long)Convert.ToDouble(Console.ReadLine());
int[] width = new int[N];
for(long i=0; i < N; i++)
{
width[i] = Convert.ToInt32(Console.ReadLine());
}
ServiceLane myServiceLane = new ServiceLane(N, T, width);
for(long testCaseNum=0; testCaseNum < T; testCaseNum++)
{
long i = (long)Convert.ToDouble(Console.ReadLine());
long j = (long)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The Output is:");
Console.WriteLine("{0}",myServiceLane.findLargestVehicle(i, j));
}
Console.ReadLine();
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Service Lane
You are viewing a single comment's thread. Return to all comments →
Hello,
I am solving this challenge in C#.I am getting stuck with the input, which is why I am unable to submit my code. Any help would be appreciated. Following is my code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace ServiceLane { class Program { public class ServiceLane { long N; long T; int[] width;
}