Skip to content

Missing edge case in Encode/Decode Strings – delimiter conflict #4297

Open
@AditKumar16122005

Description

@AditKumar16122005

The current test cases do not seem to cover inputs where the strings include the character '?', which is used as a delimiter in my submitted solution
for this input vector strs = {"what?", "really?"}; due to lack of edge test case the code passes

class Solution {
public:

string encode(vector<string>& strs) {
    string tr="";
    for(string s : strs){
        tr=tr+s+"?";
    }
    return tr;
}

vector<string> decode(string s) {
    vector<string> v;
     string ss="";
    for(char ch : s){
        if(ch!='?'){
            ss=ss+ch;
        }
        else{
            v.push_back(ss);
            ss="";
        }
    }
    return v;
}

};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions