Skip to content

Bug Report for top-k-elements-in-list #4012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
devprabal opened this issue Apr 6, 2025 · 0 comments
Open

Bug Report for top-k-elements-in-list #4012

devprabal opened this issue Apr 6, 2025 · 0 comments

Comments

@devprabal
Copy link

Bug Report for https://neetcode.io/problems/top-k-elements-in-list

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.?title=Bug Report for string-encode-and-decode

doesn't compile on the needcode platform, while it complies on my local machine and also on godbolt.org.

class Solution {
public:

    string encode(vector<string>& strs) {
        string result = "";
        for(auto& s: strs) {
            result += "#";
            result += std::to_string(s.size());
            result += "$";
            result += s;
        }
        return result;
    }

    vector<string> decode(string s) {
        vector<string> result;
        string ans = "";
        string len = "";
        bool found_start = false;
        int l = 0;
        for(int i =0; i < (int)s.length(); i++) {
            if(l == 0)
            {
                if(s[i] == '#') {
                    found_start = true;
                    continue;
                }
                if(s[i] == '$') {
                    l = atoi(len.c_str());
                    len.clear();
                    found_start = false;
                    if(l == 0) {
                        result.push_back("");
                    }
                    continue;
                }
                if(found_start) {
                    len += s[i];
                }
            }
            if(l > 0) {
                while(l) {
                    ans += s[i];
                    i++;
                    l--;
                }
                result.push_back(ans);
                ans.clear();
                i--;
            }

        }
        return result;
    }
};

compile logs from neetcode -

main.cpp:56:28: warning: missing terminating ' character
   56 |                 if(s[i] == '
      |                            ^
main.cpp:56:28: error: missing terminating ' character
main.cpp: In member function ‘std::vector<std::__cxx11::basic_string<char> > Solution::decode(std::string)’:
main.cpp:58:26: error: expected primary-expression before ‘readInput’
   58 | std::vector<std::string> readInput() {
      |                          ^~~~~~~~~
main.cpp:58:25: error: expected ‘)’ before ‘readInput’
   58 | std::vector<std::string> readInput() {
      |                         ^~~~~~~~~~
      |                         )
main.cpp:56:19: note: to match this ‘(’
   56 |                 if(s[i] == '
      |                   ^

link for godbolt

this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant