Sort by

recency

|

1305 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/iuLCUdG77yQ You will need to update the serviLane function by adding the width vector, since it was forgotten.

    vector<int> serviceLane(int n, vector<vector<int>> cases, vector<int> width) {
        vector<int> result;
        for(auto cas: cases){
            int r = width[cas[0]];
            for(int i = cas[0]; i <= cas[1]; i++){
                r = min(r, width[i]);
            }
            result.push_back(r);
        }
        return result;
    }
    
  • + 0 comments

    three js gltf viewer model editor

  • + 0 comments

    it running quiet slow

    def serviceLane(width, cases):
      return [min(width[i[0]:i[1]+1])for i in cases]
    
  • + 0 comments
    import java.io.*;
    import java.math.*;
    import java.security.*;
    import java.text.*;
    import java.util.*;
    import java.util.concurrent.*;
    import java.util.regex.*;
    
    class Result {
        public static List<Integer> serviceLane(int n, List<List<Integer>> cases,List<Integer> width ) {
        // Write your code here
        int start, end;
        
        List<Integer> res= new ArrayList<Integer>(); 
            for(int i=0;i<cases.size();i++){
                int min=Integer.MAX_VALUE;
                start=cases.get(i).get(0);
                end= cases.get(i).get(1);
                while(start<=end)
                {
                    if(min>width.get(start))
                    min=width.get(start);
                    start++;
                }
                res.add(min);
                
            }
            return res;
        }
    
    }
    
    public class Solution {
        public static void main(String[] args) throws IOException {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
    
            String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
    
            int n = Integer.parseInt(firstMultipleInput[0]);
    
            int t = Integer.parseInt(firstMultipleInput[1]);
    
            String[] widthTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
    
            List<Integer> width = new ArrayList<>();
    
            for (int i = 0; i < n; i++) {
                int widthItem = Integer.parseInt(widthTemp[i]);
                width.add(widthItem);
            }
    
            List<List<Integer>> cases = new ArrayList<>();
    
            for (int i = 0; i < t; i++) {
                String[] casesRowTempItems = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
    
                List<Integer> casesRowItems = new ArrayList<>();
    
                for (int j = 0; j < 2; j++) {
                    int casesItem = Integer.parseInt(casesRowTempItems[j]);
                    casesRowItems.add(casesItem);
                }
    
                cases.add(casesRowItems);
            }
    
            List<Integer> result = Result.serviceLane(n, cases, width);
    
            for (int i = 0; i < result.size(); i++) {
                bufferedWriter.write(String.valueOf(result.get(i)));
    
                if (i != result.size() - 1) {
                    bufferedWriter.write("\n");
                }
            }
    
            bufferedWriter.newLine();
    
            bufferedReader.close();
            bufferedWriter.close();
        }
    }
    
  • + 0 comments
    int* serviceLane(int n, int cases_rows, int cases_cols, int* width, int cases[][2], int* result_count) {
        int* result = (int*)malloc(cases_rows * sizeof(int));
        for (int i = 0; i < cases_rows; i++) {
            int min_width = width[cases[i][0]];
            for (int j = cases[i][0]; j <= cases[i][1]; j++) {
                if (width[j] < min_width) {
                    min_width = width[j];
                }
            }
            result[i] = min_width;
        }
        *result_count = cases_rows;
        return result;
    }
    
    int main() {
        int n, t;
        scanf("%d %d", &n, &t);
        int width[n];
        for (int i = 0; i < n; i++) {
            scanf("%d", &width[i]);
        }
        int cases[t][2];
        for (int i = 0; i < t; i++) {
            scanf("%d %d", &cases[i][0], &cases[i][1]);
        }
        int result_count;
        int* result = serviceLane(n, t, 2, width, cases, &result_count);
        for (int i = 0; i < result_count; i++) {
            printf("%d\n", result[i]);
        }
        free(result);
    		#Pratham Gupta
        return 0;
    }