Sort by

recency

|

1316 Discussions

|

  • + 0 comments

    The problem is incorrect with its parameter, fix it by including width vector in parameter and passing the calculated width vector through main function.

    Problem is insolvable without width so do not waste time figuring alternative.

    Spoiler: Solution in rust:

    fn serviceLane(n: i32, width: &Vec<i32>, cases: &[Vec<i32>]) -> Vec<i32> {
        let mut returnVector: Vec<i32> = Vec::new();
    
        for case in cases {
            let entry: usize = case[0] as usize;
            let exit: usize = case[1] as usize;
    
            let mut minimum = width[entry];
            for index in entry + 1..=exit {
                if width[index] < minimum {
                    minimum = width[index];
                }
            }
    
            returnVector.push(minimum);
        }
    
        returnVector
    }
    
  • + 0 comments

    Here is my Python solution! I think there was a mistake in the code where the function should take the width and the cases, not n and the cases.

    def serviceLane(width, cases):
        return [min(width[c[0]:c[1] + 1]) for c in cases]
    
  • + 0 comments
    def serviceLane(n, cases):
        results=[]
        #here the cases array is an 2d array so we have to handle it properly 
        for j in cases:
             #here the 3 is the highest width so assign it to the m_w 
            m_w=3
            for i in range(j[0],j[1]+1):
                if width[i]<m_w:
                    m_w=width[i]
            results.append(m_w)           
        return results
        ``
    
  • + 0 comments

    Python

    The question parameter itself wrong, pass width and cases not n

    def serviceLane(width, cases):
        # Write your code here
        all_width = []
        for each_case in cases:
            min_width = min(width[each_case[0]:each_case[1]+1])
            all_width.append(min_width)
        return all_width
    
  • + 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;
    }