Sort by

recency

|

1310 Discussions

|

  • + 0 comments

    JavaCode

    import java.util.*;
    
    public class trys {
    
        public static List<Integer> serviceLane(int n, int[][] cases, int[] width){
            List<Integer> list = new ArrayList<>();
            for(int i=0;i<cases.length;i++){
                    // 00 01
                    // 10 11
                    int min = Integer.MAX_VALUE;
                    // List<Integer> minlist = new ArrayList<>();
                    for(int k = cases[i][0];k<=cases[i][1];k++){
                        min = Math.min(min,width[k]);
                    }
                    list.add(min);
            }
            return list;
        }
    
        public static void main(String[] args) {
            Scanner s = new Scanner(System.in);
            int n = s.nextInt();
            int testcase = s.nextInt();
            int[] width = new int[n];
            for(int i=0;i<n;i++){
                width[i] = s.nextInt();
            }
            int[][] cases = new int[testcase][2];
            for(int i=0;i<testcase;i++){
                for(int j=0;j<2;j++){
                    cases[i][j] = s.nextInt();
                }
            }
            List<Integer> result = serviceLane(n, cases, width);
            for(int i=0;i<result.size();i++){
                System.out.println(result.get(i));
            }
        }
    }
    
  • + 0 comments

    javascript code correction

    line 34 ;- add width parameter in the function =>

    function serviceLane(n, cases, width) {

    line 56 :- add width in calling function ( this line number may vary)

    function serviceLane(n, cases,width) { let res=[]

    for(let i=0;i<cases.length;i++){
        let slice= width.slice(cases[i][0],cases[i][1]+1)
        let min=Infinity
        for(let j=0;j<slice.length;j++){
            if(slice[j]<min){
                min=slice[j]
            }
        }
         res.push(min)
    }
    
    return res
    

    `

  • + 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
    def serviceLane(n, cases):
        res=[]
        for c in cases:
            x=width[c[0]:c[1]+1]
            res.append(min(x))
        return res
    
  • + 0 comments

    could this code be integrated into a platform like NIF Portugal to manage or optimize routing algorithms or similar functionalities? Any thoughts on the best way to approach this?