We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Strings
- Morgan and a String
- Discussions
Morgan and a String
Morgan and a String
Sort by
recency
|
311 Discussions
|
Please Login in order to post a comment
solution in scala
def morganAndString(inputA: String, inputB: String): String = { var posA = 0 var posB = 0 val sb = new StringBuilder(inputA.length + inputB.length)
Do you have any idea why i'm getting just half of the test cases? def morganAndString(a, b):
Could any one give a simple case that might fail this logic? def morganAndString(a, b): j=0 k=0 c=[] while jb[k:]: c+=b[k] k+=1 if j
Use this C++ Code
Optimized String Comparison: The compare function is designed to handle cases where characters from both strings are equal. This function looks ahead to decide the correct sequence to maintain the lexicographical order.
Efficient Memory Management: The result string's memory is reserved upfront to avoid frequent reallocation, improving performance.
Handling Ties: When characters are equal, the program checks further along the strings to determine which string to continue with, ensuring the smallest lexicographical result.
so use this for good solution