The Longest Staircase
InterviewTime limit1sMemory limit128 MB
Given k cards with distinct values 1 to n plus one blank card (0) you can set to any value, find the longest run of consecutive integers formable.
- Level
Medium4 of 10
- Topics
- Sorting, Two pointers, Implementation
- Solved
- No attempts yet
Problem
There are cards, each showing a distinct integer from to , plus one blank card, for cards in total. Out of these cards, of them are given to you (). On the blank card you may write any single integer from to .
Using only the given cards, you want to form the longest possible run of consecutive integers. Given the cards, write a program that prints the maximum length of a consecutive integer sequence that can be formed from them.
Input
The first line contains two integers () and (), in this order, separated by a single space. Each of the next lines contains one integer describing the value on one of the given cards. The blank card is represented by .
Output
Print a single line containing one integer: the maximum length of a consecutive integer sequence that can be formed.