Ad
  • Custom User Avatar

    to anyone wanting to adress this: I bet the error is due to the user's code, but the initial solution in cpp isn't valid anyway: both sample tests and full test suite give:

    In file included from main.cpp:6:
    ./solution.cpp:1:21: error: unknown type name 'string'; did you mean 'std::string'?
    char triangle(const string &row)
                        ^~~~~~
                        std::string
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stringfwd.h:79:33: note: 'std::string' declared here
      typedef basic_string<char>    string;   
                                    ^
    In file included from main.cpp:6:
    ./solution.cpp:1:29: warning: unused parameter 'row' [-Wunused-parameter]
    char triangle(const string &row)
                                ^
    1 warning and 1 error generated.
    
  • Default User Avatar

    I've got a big error from the tests:

    In file included from main.cpp:1:
    In file included from /usr/local/include/igloo/igloo_alt.h:10:
    In file included from /usr/local/include/igloo/igloo_framework.h:22:
    In file included from /usr/local/include/igloo/external/snowhouse/snowhouse.h:4:
    In file included from /usr/local/include/igloo/external/snowhouse/fluent/fluent.h:9:
    In file included from /usr/local/include/igloo/external/snowhouse/fluent/expressionbuilder.h:9:
    In file included from /usr/local/include/igloo/external/snowhouse/fluent/../constraints/constraints.h:11:
    /usr/local/include/igloo/external/snowhouse/fluent/../constraints/equalsconstraint.h:24:26: error: invalid operands to binary expression ('const char' and 'const std::__cxx11::basic_string')
    return (m_expected == actual);
    ~~~~~~~~~~ ^ ~~~~~~
    /usr/local/include/igloo/external/snowhouse/assert.h:126:12: note: in instantiation of function template specialization 'snowhouse::EqualsConstraint::operator()<std::__cxx11::basic_string >' requested here
    if (!expression(actual))
    ^
    /usr/local/include/igloo/external/snowhouse/assert.h:135:7: note: in instantiation of function template specialization 'snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That<std::__cxx11::basic_string, snowhouse::EqualsConstraint, std::__cxx11::basic_string ()>' requested here
    That(actual, expression, detail::EmptyMessage, file_name, line_number);
    ^
    ./tests.cpp:8:13: note: in instantiation of function template specialization 'snowhouse::ConfigurableAssertsnowhouse::DefaultFailureHandler::That<std::__cxx11::basic_string, snowhouse::EqualsConstraint >' requested here
    Assert::That(triangle(c.first), Equals(c.second));
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/allocator.h:156:7: note: candidate function not viable: no known conversion from 'const char' to 'const std::allocator' for 1st argument
    operator==(const allocator&, const allocator&) _GLIBCXX_NOTHROW
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/system_error:292:3: note: candidate function not viable: no known conversion from 'const char' to 'const std::error_code' for 1st argument
    operator==(const error_code& __lhs, const error_code& __rhs) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/system_error:297:3: note: candidate function not viable: no known conversion from 'const char' to 'const std::error_code' for 1st argument
    operator==(const error_code& __lhs, const error_condition& __rhs) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/system_error:304:3: note: candidate function not viable: no known conversion from 'const char' to 'const std::error_condition' for 1st argument
    operator==(const error_condition& __lhs, const error_code& __rhs) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/system_error:311:3: note: candidate function not viable: no known conversion from 'const char' to 'const std::error_condition' for 1st argument
    operator==(const error_condition& __lhs,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/postypes.h:222:5: note: candidate template ignored: could not match 'fpos' against 'const char'
    operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_pair.h:448:5: note: candidate template ignored: could not match 'pair<type-parameter-0-0, type-parameter-0-1>' against 'const char'
    operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_iterator.h:325:5: note: candidate template ignored: could not match 'reverse_iterator' against 'const char'
    operator==(const reverse_iterator<_Iterator>& __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_iterator.h:363:5: note: candidate template ignored: could not match 'reverse_iterator' against 'const char'
    operator==(const reverse_iterator<_IteratorL>& __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_iterator.h:886:5: note: candidate template ignored: could not match '__normal_iterator<type-parameter-0-0, type-parameter-0-2>' against 'const char'
    operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_iterator.h:893:5: note: candidate template ignored: could not match '__normal_iterator<type-parameter-0-0, type-parameter-0-1>' against 'const char'
    operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_iterator.h:1139:5: note: candidate template ignored: could not match 'move_iterator' against 'const char'
    operator==(const move_iterator<_IteratorL>& __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_iterator.h:1145:5: note: candidate template ignored: could not match 'move_iterator' against 'const char'
    operator==(const move_iterator<_Iterator>& __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/ext/new_allocator.h:167:2: note: candidate template ignored: could not match 'new_allocator' against 'basic_string'
    operator==(const new_allocator&, const new_allocator<_Up>&)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/allocator.h:168:5: note: candidate template ignored: could not match 'allocator' against 'const char'
    operator==(const allocator<_T1>&, const allocator<_T2>&)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/string_view:473:5: note: candidate template ignored: could not match 'basic_string_view<type-parameter-0-0, type-parameter-0-1>' against 'char'
    operator==(basic_string_view<_CharT, _Traits> __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/string_view:479:5: note: candidate template ignored: could not match 'basic_string_view<type-parameter-0-0, type-parameter-0-1>' against 'char'
    operator==(basic_string_view<_CharT, _Traits> __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/string_view:485:5: note: candidate template ignored: could not match 'basic_string_view' against 'basic_string'
    operator==(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6141:5: note: candidate template ignored: could not match 'basic_string<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>' against 'const char'
    operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6149:5: note: candidate template ignored: could not match 'basic_string<type-parameter-0-0, char_traits, allocator >' against 'const char'
    operator==(const basic_string<_CharT>& __lhs,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6163:5: note: candidate template ignored: could not match 'const _CharT ' against 'char'
    operator==(const _CharT
    __lhs,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/basic_string.h:6175:5: note: candidate template ignored: could not match 'basic_string<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>' against 'const char'
    operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/streambuf_iterator.h:208:5: note: candidate template ignored: could not match 'istreambuf_iterator<type-parameter-0-0, type-parameter-0-1>' against 'const char'
    operator==(const istreambuf_iterator<_CharT, _Traits>& __a,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/optional:983:5: note: candidate template ignored: could not match 'optional' against 'const char'
    operator==(const optional<_Tp>& __lhs, const optional<_Up>& __rhs)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/optional:1034:5: note: candidate template ignored: could not match 'optional' against 'const char'
    operator==(const optional<_Tp>& __lhs, nullopt_t) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/optional:1039:5: note: candidate template ignored: could not match 'optional' against 'basic_string'
    operator==(nullopt_t, const optional<_Tp>& __rhs) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/optional:1095:5: note: candidate template ignored: could not match 'optional' against 'const char'
    operator==(const optional<_Tp>& __lhs, const _Up& __rhs)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/optional:1101:5: note: candidate template ignored: could not match 'optional' against 'basic_string'
    operator==(const _Up& __lhs, const optional<_Tp>& __rhs)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/array:252:5: note: candidate template ignored: could not match 'array<type-parameter-0-0, _Nm>' against 'const char'
    operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/tuple:1419:5: note: candidate template ignored: could not match 'tuple<type-parameter-0-0...>' against 'const char'
    operator==(const tuple<_TElements...>& __t,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_map.h:1455:5: note: candidate template ignored: could not match 'map<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2, type-parameter-0-3>' against 'const char'
    operator==(const map<_Key, _Tp, _Compare, _Alloc>& __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_multimap.h:1119:5: note: candidate template ignored: could not match 'multimap<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2, type-parameter-0-3>' against 'const char'
    operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_vector.h:1888:5: note: candidate template ignored: could not match 'vector<type-parameter-0-0, type-parameter-0-1>' against 'const char'
    operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_deque.h:286:5: note: candidate template ignored: could not match '_Deque_iterator<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>' against 'const char'
    operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_deque.h:293:5: note: candidate template ignored: could not match '_Deque_iterator<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>' against 'const char'
    operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_deque.h:2312:5: note: candidate template ignored: could not match 'deque<type-parameter-0-0, type-parameter-0-1>' against 'const char'
    operator==(const deque<_Tp, _Alloc>& __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_stack.h:313:5: note: candidate template ignored: could not match 'stack<type-parameter-0-0, type-parameter-0-1>' against 'const char'
    operator==(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_list.h:1991:5: note: candidate template ignored: could not match 'list<type-parameter-0-0, type-parameter-0-1>' against 'const char'
    operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/unique_ptr.h:715:5: note: candidate template ignored: could not match 'unique_ptr<type-parameter-0-0, type-parameter-0-1>' against 'const char'
    operator==(const unique_ptr<_Tp, _Dp>& __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/unique_ptr.h:721:5: note: candidate template ignored: could not match 'unique_ptr<type-parameter-0-0, type-parameter-0-1>' against 'const char'
    operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/unique_ptr.h:726:5: note: candidate template ignored: could not match 'unique_ptr' against 'basic_string'
    operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/shared_ptr_base.h:1412:5: note: candidate template ignored: could not match '__shared_ptr<type-parameter-0-0, _Lp>' against 'const char'
    operator==(const __shared_ptr<_Tp1, _Lp>& __a,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/shared_ptr_base.h:1418:5: note: candidate template ignored: could not match '__shared_ptr<type-parameter-0-0, _Lp>' against 'const char'
    operator==(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/shared_ptr_base.h:1423:5: note: candidate template ignored: could not match '__shared_ptr' against 'basic_string'
    operator==(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/shared_ptr.h:383:5: note: candidate template ignored: could not match 'shared_ptr' against 'const char'
    operator==(const shared_ptr<_Tp>& __a, const shared_ptr<_Up>& __b) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/shared_ptr.h:388:5: note: candidate template ignored: could not match 'shared_ptr' against 'const char'
    operator==(const shared_ptr<_Tp>& __a, nullptr_t) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/shared_ptr.h:393:5: note: candidate template ignored: could not match 'shared_ptr' against 'basic_string'
    operator==(nullptr_t, const shared_ptr<_Tp>& __a) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/std_function.h:746:5: note: candidate template ignored: could not match 'function<type-parameter-0-0 (type-parameter-0-1...)>' against 'const char'
    operator==(const function<_Res(_Args...)>& __f, nullptr_t) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/std_function.h:752:5: note: candidate template ignored: could not match 'function' against 'basic_string'
    operator==(nullptr_t, const function<_Res(_Args...)>& __f) noexcept
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/unordered_map.h:2091:5: note: candidate template ignored: could not match 'unordered_map<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2, type-parameter-0-3, type-parameter-0-4>' against 'const char'
    operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/unordered_map.h:2103:5: note: candidate template ignored: could not match 'unordered_multimap<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2, type-parameter-0-3, type-parameter-0-4>' against 'const char'
    operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
    ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stream_iterator.h:134:5: note: candidate template ignored: could not match 'istream_iterator<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2, type-parameter-0-3>' against 'const char'
    operator==(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x,
    ^
    1 error generated. '''

  • Default User Avatar

    Indeed, it is much simpler than it seemed at first, I managed to solve it, thanks for the reply.

  • Default User Avatar

    Hi - your current approach is basically a brute force search (it is trying all possible combinations of subarrays effectively), so it will indeed get the correct solution.

    However, the large random tests involve lists with up to 50,000 elements - if you perform the brute force approach you will therefore need to perform 50,000 ** 2 operations approximately, for each test, which is a huge number.

    That's why you are timing out; your solution is correct, but inefficient.

    To answer your question for advice about this; you cannot really speed up your current brute force approach - instead, you need to reduce the time complexity from O(n^2) to something less than O(n^2).

  • Default User Avatar

    I have the same problem as @eshis with python, everything seems to work excluding last random test.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
    1. Make showing array to log (For example C#: System.Console.WriteLine(string.Join(", ", arr)));
    2. Copy
    3. Try again
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution