Menu
Coddy logo textTech

Happy Subsequence

Lesson 23 of 25 in Coddy's Coding Problems: Volume 2 course.

A sequence of numbers is called a 'happy sequence' if it contains the number 3 exactly three times. Given a sequence of random numbers ranging from 1 to 20, your task is to find the length of the longest subarray or subsequence that includes the number 3 exactly three times.

challenge icon

Challenge

Hard

Write a program that reads a natural number N from the input, followed by N numbers representing the sequence. Output the length of the longest subsequence that contains the number 3 exactly three times.

Input
8
1 3 3 2 3 3 1 4

Output
6
Explanation
The subsequence 3 2 3 3 1 4 is the longest subsequence containing exactly three 3s, and its length is 6

Try it yourself

#include <stdio.h>

int main() {
    // Write code here
    return 0;
}

All lessons in Coding Problems: Volume 2