Sort by

recency

|

118 Discussions

|

  • + 0 comments

    Is it just me or should test Case 0 and 11 should have zero as the answer? the queestion state you want strcitly greater than not equal? Since 0 and 11 are just huge inputs of the same number there is no a_j or a_k that is greater than a__i

  • + 0 comments

    hello, this is really weird. This solution scores 100% Yet if you test it with inputs : 5 2 1 1 1 5 It should return 5, and yet it returns 0

    def solve(arr):
        left = []
        right = []
        n = len(arr)
        for i,e in enumerate(arr):
            if i==0 or e>= arr[i-1]:
                left.append(0)
            else:
                left.append(i)
            if i== n-1 or e>=arr[i + 1]:
                right.append(0)
            else:
                right.append(i+2)
        return max([left[i]*right[i] for i in range(n)])
    
  • + 1 comment

    This is my solution in python3

    import math
    import os
    import random
    import re
    import sys
    from typing import List
    
    def optimal(array: List):
        returned_values_left: list[int] = []
        returned_values_right: list[int] = []
        for index, item in enumerate(array):
            if index == 0:
                returned_values_left.append(0)
            else:
                if item < array[index - 1]:
                    returned_values_left.append(index)
                else:
                    returned_values_left.append(0)
    
            if index == len(array)-1:
                returned_values_right.append(0)
            else:
                if item < array[index + 1]:
                    returned_values_right.append(index + 2)
                else:
                    returned_values_right.append(0)
        return [returned_values_left,returned_values_right]
        
    #
    # Complete the 'solve' function below.
    #
    # The function is expected to return an INTEGER.
    # The function accepts INTEGER_ARRAY arr as parameter.
    #
    
    def solve(arr):
        # Write your code here
        value = sys.maxsize * -1
        [left,right] = optimal(arr)
    
        for position in range(len(arr)):
            new_value = left[position] * right[position]
            if new_value > value:
                value = new_value
    
        return value
    
  • + 0 comments

    i have 4 test cases failing in python . Kudos to who ever got it working for all test cases and thanks for sharing the solution.Good to know there's a solution.

    Gist for 4 failing test cases

  • + 0 comments

    C++ solution, need to change all int to long to pass all test cases

    #include <bits/stdc++.h>
    
    using namespace std;
    
    string ltrim(const string &);
    string rtrim(const string &);
    vector<string> split(const string &);
    
    long long solve(vector<long> arr) {
        vector<long> prevBigger(arr.size() + 1);
        vector<long> nextBigger(arr.size() + 1);
        for (int i =2; i<= arr.size(); i++ ){
            if (arr[i - 1] < arr[i - 2]) {
                prevBigger[i] = i - 1;
            } else {
                long it = prevBigger[i - 1];
                
                while (arr[it - 1] < arr[i - 1] && it != 0) {
                    it = prevBigger[it];
                }
                
                prevBigger[i] = prevBigger[it];
            } 
        } 
        
        for (int i = arr.size() - 1; i >= 1; i--) {
            if (arr[i] > arr[i - 1]) {
                nextBigger[i] = i+ 1;
            } else {
                long it = nextBigger[i+1];
                while (it != 0 && arr[i - 1] > arr[it - 1]) {
                    it = nextBigger[it];
                }
                nextBigger[i] = nextBigger[it];
            }
        }
        long long res = 0;
        for (int i = 1; i<= arr.size(); i++) {
            long long t = prevBigger[i] * nextBigger[i];
            if (t > res) {
                res = t;
            }
        }
        return res;
    }
    
    int main()
    {
        // std::ifstream in("input.txt");
        // std::streambuf *cinbuf = std::cin.rdbuf(); //save old buf
        // std::cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
        
        // std::ofstream fout("output.txt");
        ofstream fout(getenv("OUTPUT_PATH"));
    
        string arr_count_temp;
        getline(cin, arr_count_temp);
    
        int arr_count = stoi(ltrim(rtrim(arr_count_temp)));
    
        string arr_temp_temp;
        getline(cin, arr_temp_temp);
    
        vector<string> arr_temp = split(rtrim(arr_temp_temp));
    
        vector<long> arr(arr_count);
    
        for (int i = 0; i < arr_count; i++) {
            long arr_item = stol(arr_temp[i]);
    
            arr[i] = arr_item;
        }
    
        long long result = solve(arr);
    
        fout << result << "\n";
    
        fout.close();
    
        return 0;
    }
    
    string ltrim(const string &str) {
        string s(str);
    
        s.erase(
            s.begin(),
            find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
        );
    
        return s;
    }
    
    string rtrim(const string &str) {
        string s(str);
    
        s.erase(
            find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
            s.end()
        );
    
        return s;
    }
    
    vector<string> split(const string &str) {
        vector<string> tokens;
    
        string::size_type start = 0;
        string::size_type end = 0;
    
        while ((end = str.find(" ", start)) != string::npos) {
            tokens.push_back(str.substr(start, end - start));
    
            start = end + 1;
        }
    
        tokens.push_back(str.substr(start));
    
        return tokens;
    }