HackerRank "Richie Rich"
2017-12-23 10:32
399 查看
Fun Greedy. My first thought was a DFS based solution... however the editorial provides a super neat 2-pass O(n) solution:
Pass 1: if s[l] != s[r], change the smaller one into the bigger one.
Pass 2: check k. if k > 0, we change as many chars into '9'
Split one convoluted problem into 2 easier one.
Pass 1: if s[l] != s[r], change the smaller one into the bigger one.
Pass 2: check k. if k > 0, we change as many chars into '9'
Split one convoluted problem into 2 easier one.
相关文章推荐
- HackerRank - "String Modification"
- HackerRank "The Great XOR"
- HackerRank "Minimum Penalty Path"
- HackerRank "Organizing Containers of Balls"
- HackerRank "Bike Racer"
- HackerRank "Hamming Distance"
- HackerRank - "Hexagonal Grid"
- HackerRank "Favorite sequence"
- HackerRank "Kundu and Tree" !!
- HackerRank "Palindrome Index"
- HackerRank "Lucky Numbers"
- HackerRank "Morgan and a String"
- HackerRank "Permutation game"
- HackerRank "Poisonous Plants"
- HackerRank - "Detect HTML Attributes"
- HackerRank "Vertical Rooks"
- HackerRank "Triangle Numbers"
- HackerRank "The Indian Job"
- HackerRank - "Two arrays"
- HackerRank - "Algorithmic Crush"