- Prepare
- Algorithms
- Strings
- Morgan and a String
- Discussions
Morgan and a String
Morgan and a String
+ 0 comments I'm wondering why this doesn't work :
function morganAndString(a, b) { let buildString = ''; while (a && b) { if (a < b) { buildString += a[0]; a = a.substring(1); } else { buildString += b[0]; b = b.substring(1); } } if (a) { buildString += a; } else if (b) { buildString += b; } return buildString;
I would expect it to work since it's quite similar to some of the solution, the main difference is to not add the 'z' for the compare. Instead if one of the string is empty, I stop looping, and add to the rest of the string the other string. However this doesn't work, and I am not sure why
+ 0 comments hi, i am new face here this is some test result: abcd aef -> aabcdef
abcdhj aef -> aabcdefhj
abcdhj aefo -> aabcdefhjo
when i submit: all wrong, do i miss any basic case or do i misunderstand something? thanks
+ 0 comments Here is my solution in java, javascript, python, C, C++, Csharp HackerRank Morgan and a String Problem Solution
+ 0 comments One more thing that i see was not mentioned, they talk about stacks however the problem statement is a bit confusing in this regard. he problem describes the given strings as "stacks", which implies a LIFO (last-in, first-out) data structure, while the processing order is FIFO (first-in, first-out). This seems contradictory. To clarify, we can think of the given strings as a "stack of cards" where we can only pick the top card. However, the order in which we pick the cards can follow a FIFO approach. This is similar to how we can access the elements of a queue in a LIFO manner by using a stack data structure.
very bad problem description.
So, in essence, the problem is asking us to pick elements from the given strings in a specific order (FIFO), but we can only access the top element of each string, which is why the problem describes them as "stacks".
+ 1 comment Here is the solution of Morgan and a String Click Here
Sort 290 Discussions, By:
Please Login in order to post a comment