A company is planning to provide an extra discount to it's customers. Every order has an order ID associated with it which is a sequence of digits. The discount is calculated as the count of unique repeating digits in the order ID. Write a code to find the discount percentile given to the customers.
public class Main {
public static int getDiscount(String id) {
int[] counts = new int[10];
int discount = 0;
for (int i = 0; i < id.length(); i++) {
counts[id.charAt(i) - '0']++;
}
for (int i = 0; i < counts.length; i++) {
if (counts[i] > 1) {
discount++;
}
}
return discount;
}
}
Comments
Leave a comment