Untitled

 avatar
unknown
java
19 days ago
1.2 kB
2
Indexable
import java.util.Scanner;

public class FootpathBeauty {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        // Input number of blocks (n) and number of colors (k)
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        // Input the block colors
        int[] blockColors = new int[n];
        for (int i = 0; i < n; i++) {
            blockColors[i] = sc.nextInt();
        }
        
        // Input the chief guest's favorite color
        int favoriteColor = sc.nextInt();
        
        // Find the largest number of contiguous blocks with the favorite color
        int maxBeauty = 0, currentCount = 0;
        for (int i = 0; i < n; i++) {
            if (blockColors[i] == favoriteColor) {
                currentCount++;
                maxBeauty = Math.max(maxBeauty, currentCount);
            } else {
                currentCount = 0; // Reset the count for non-favorite color blocks
            }
        }
        
        // Output the beauty value
        System.out.println(maxBeauty);
        
        sc.close();
    }
}
Leave a Comment