Challenges with std::string
appunto
Solutions to Special String Again
- Solution1
- Complexity: O(N) time and O(1) Space
Solutions to String Reverse Challenge at Hackerrank
- String Reverse1 and two problems are solved
- The char by char string reversion
- It is simply solved with an
O(N)
loop fromrbegin()
torend()
- The word by word string reversion
- It is solved with a 2 step approach
- First an
O(N)
char by char string reversion using the previous solution - Then an
O(N)
word explode, usinggetline()
specifing the ' ' delimiter and reversing each specific word
- First an
- The Substring finding in 2 Strings on Hackerrank
- The goal is to check if 2 substrings has a common string but not to return the actual substring
- This makes the actual problem much easier than it seems as a necessary and sufficient condition is they share a char so the proposed solution1 focuses on solving this equivalent challenge
- It is implemented representing a string as an unordered_map of its chars (store O(1), loop O(N)) and then iterating over the other string looking up for each char in the other string (lookup O(1), loop O(N))