#32Warehouse Barcode Verification
A warehouse automation system uses numeric barcodes to identify packages. Before a package is accepted, a scanning system compares the registered barcode with the barcode detected by a warehouse scanner. You are given two strings, registeredCode and scannedCode, of equal length. For every position: An exact match occurs when the digit in scannedCode is the same as the digit in registeredCode at the same position.
A misplaced match occurs when a digit from scannedCode appears in registeredCode but is located at a different position. A digit already counted as an exact match cannot be counted again. Return the verification result in the format: "xEyM" where: x = number of exact matches, y = number of misplaced matches. Repeated digits must be handled correctly.
Real-World Applications: Automated Package Verification Manufacturing Quality Control Logistics and Sorting Systems
Examples
Example 1
Input: registeredCode = "1807"
scannedCode = "7810"
Output: "1E3M"
Explanation: There is 1 exact match and 3 misplaced matches.
Example 2
Input: registeredCode = "1123"
scannedCode = "0111"
Output: "1E1M"
Explanation: Only one of the remaining 1s can be counted as a misplaced match.
Example 3
Input: registeredCode = "1234"
scannedCode = "1234"
Output: "4E0M"
Explanation: All four digits are exact matches.
Constraints
- 1 <= registeredCode.length <= 1000
- registeredCode.length == scannedCode.length
- registeredCode contains only digits '0' to '9'
- scannedCode contains only digits '0' to '9'
- Leading zeros are allowed because the barcodes are represented as strings.
- Each digit can contribute to at most one match.
- Exact matches must be counted before misplaced matches.
