Service Lane

A driver is driving on the freeway. The check engine light of his vehicle is on, and the driver wants to get service immediately. Luckily, a service lane runs parallel to the highway. It varies in width along its length.

You will be given an array of widths at points along the road (indices), then a list of the indices of entry and exit points. Considering each entry and exit point pair, calculate the maximum size vehicle that can travel that segment of the service lane safely.

Example:

Input:  n=8,t=5,arr[n]={2,3,1,2,3,2,3,3}, cases={{0,3},{4,6},{6,7},{3,5},{0,7}}
Output: 1
2
3
2
1

Approach

C++

#include <bits/stdc++.h>
using namespace std;

void bubble_sort(long int a[], long int n)
{
    int roundjtemp;
    for (round = 1round <= n - 1round++)
    {
        for (j = 0j <= n - 1 - roundj++)
        {
            if (a[j] > a[j + 1])
            {
                temp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
            }
        }
    }
}

int main()
{
    long int n = 8t = 5xijky;
    long int a[n] = {23123233};
    vector<vector<int>> cases = {{03}, {46}, {67}, {35}, {07}};
    long int c[n];
    for (x = 0x < nx++)
    {
        c[x] = 0;
    }
    for (x = 0x < tx++)
    {
        i = cases[x][0];
        j = cases[x][1];
        k = 0;
        for (y = iy <= jy++)
        {
            c[k] = a[y];
            k++;
        }
        bubble_sort(ck);
        cout << c[0<< endl;
    }
    return 0;
}


No comments:

Post a Comment