Re:Algorithms you should know before you take system design ...
by patrickthebold on Thursday August 11, 2022 @08:03PM
(#32433330)
TBH reversing a string is probably harder than the others if you consider how strange unicode is.
Re:Algorithms you should know before you take system design ...
by jonathankoren on Thursday August 11, 2022 @08:22PM
(#32433463)
str.insert("\u200F", 0).append("\u200E");
Next question. :)
Re:Algorithms you should know before you take system design ...
by naniwaduni on Thursday August 11, 2022 @08:41PM
(#32433569)
It's less that it's "hard" and more that it's generally not a sensible operation unless performed on known well-restricted domain (or if you're up to flipping an image of rendered text, I guess).
Re:Algorithms you should know before you take system design ...
by avinassh on Thursday August 11, 2022 @11:08PM
(#32434347)
How is string reversal is done with unicodes?
Re:Algorithms you should know before you take system design ...
by jonathankoren on Friday August 12, 2022 @02:24PM
(#32442192)
Combining characters are the most obvious problem.
Both of these are visually identical as "naïve", however the first is written with "ï" being a single code point, while the second is an "i" followed by a combining dieresis. In the first example, the dieresis correctly stays attached to the i, while in the second dieresis incorrectly moves to the v. To do it right, you have to scan through the string and keep the base character and all combining characters in order.
"na\u00efve".split("").reverse().join("") // CORRECT: "evïan" "ev\u00efan"
"nai\u0308ve".split("").reverse().join("") // INCORRECT: "ev̈ian". Should have been "evi\u0308an", not "ev\u0308ian".
At work, I have written and then used a bunch of these in production, just for the narrow scope of things I work on. Might be indicative of me being in a bubble though.
Please, ask me to make a bloom filter or show how consistent hashing enables sharding! I'll pass on yet another "Implement String.reverse()"