Find the maximum sequence of the same letters
Anonymous
O(n) int max_sequence(const std::string& str) { auto last = str[0]; auto max_count = 1; auto current_count = 1; for (auto i = 1; i max_count) max_count = current_count; } else { last = str[i]; current_count = 1; } } return max_count; } void run() { auto count = max_sequence("aabaaaccbbccdddeeeffffffggccdddaaamnpqrs"); }
Check out your Company Bowl for anonymous work chats.