This is a verified interview question from Arista. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Minimum Operations to Make a Palindrome" covers key patterns like Strings.
"A palindromic string needs the same forward and backward. For example, 'O', 'II', and 'OTO' are palindromes, but 'OO1' and 'IIRO' are not. You are optimizing a logging system that stores logs as binary strings. However due to a sorting bug, some logs are jumbled. For performance analytics, your system requires these binary logs to be palindromic for easier indexing and retrieval. You can perform the following operation any number of times: - swap any two different bits in the log string Implement a function to calculate the minimum number of operations required to convert the binary string into a palindrome. The function getMinOperations takes the following input: - string logData: A binary string consisting of characters 'O' and 'I'. The function should return an integer, which is the minimum number of operations required to turn it into a palindrome. If it's impossible, return -1."
Join thousands of developers practicing for Arista.