CodeDrill
day_streak: --
← 問題一覧に戻る
Python ・ Standard I/O

Problem 33: Second Largest Value

An integer N is given on the first line, and N integers separated by single spaces are given on the second line. Output, on one line, the second largest value among them.

If the same value appears multiple times, count it as one. For example, for 5 5 3 1, the values in descending order are 5, 3, 1, so the answer is 3.

Constraints

2 ≤ N ≤ 100, 0 ≤ each element ≤ 1000 (it is guaranteed that there are at least 2 distinct values)

Input example 1

5
3 1 4 1 5

Output example 1

4

Input example 2

4
5 5 3 1

Output example 2

3

What you'll train

Cover the edge cases

What you get

  • Indicate the condition for removing duplicates
  • Check boundary values
  • Specify the output format

How to ask the AI

Clearly tell the AI that when the same value appears multiple times, it should be counted as one. It's also reassuring to explain how the program should behave in cases like 5 5 3 1, where the maximum value is duplicated, or when all the values are the same.

If you ask vaguelyIf duplicates aren't removed and the values are simply sorted, a value smaller than intended may fail to be selected as the second largest when the same value repeats.

あなたのコード

実行しました

プレビュー

AIレビュー(プロンプト練習)

コードはChatGPTやClaudeに出させたものを貼って構いません。
ここでの本番は「次にAIへ出す指示」です。評価軸は1つだけ見て、弱点・指示の穴・改善例を返します。
テストに落ちていてもレビューできます。落ちた理由と、指示に足りなかった情報を結びつけます。

先にコードを実行し、テストを1つ以上通してください。