\documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage{amsmath, amssymb} \usepackage{geometry} \usepackage{fancyhdr} \usepackage{listings} \usepackage{xcolor} \usepackage{enumitem} % Page layout \geometry{margin=1in} \pagestyle{fancy} \fancyhf{} \fancyhead[L]{Programming Competition Test} \fancyhead[R]{\today} \fancyfoot[C]{\thepage} % Listings style for code \lstset{ language=Java, basicstyle=\ttfamily\small, keywordstyle=\color{blue}, commentstyle=\color{green!60!black}, stringstyle=\color{red}, numbers=left, numberstyle=\tiny, stepnumber=1, numbersep=5pt, showstringspaces=false, breaklines=true, frame=single, rulecolor=\color{black!30}, backgroundcolor=\color{black!2} } % Custom commands \newcommand{\problem}[1]{\section*{#1}} \newcommand{\inputformat}{\textbf{Input format:}} \newcommand{\outputformat}{\textbf{Output format:}} \newcommand{\examples}{\textbf{Example(s):}} \begin{document} \begin{center} {\LARGE \textbf{Programming Competition Test}}\\[2mm] {\large Duration: 2 hours \quad Total Marks: 100} \end{center} \section*{Instructions} \begin{enumerate}[label=\arabic*.] \item This test contains algorithmic problems similar to those found on LeetCode or HackerRank. \item Use efficient algorithms to avoid timeouts; naive solutions may not receive full marks. \item Submit solutions in C++, Python, or Java. \item For each problem, write a function or program according to the specified input/output format. \item Clearly comment your code if necessary. \end{enumerate} % ========================= Problem 1 ========================= \problem{Problem 1: Two Sum} \textit{Difficulty: Easy} Given an array of integers \texttt{nums} and an integer \texttt{target}, return indices of the two numbers such that they add up to \texttt{target}. Assume exactly one solution exists. \inputformat \begin{itemize} \item First line contains an integer $n$ ($2 \leq n \leq 10^5$), the size of the array. \item Second line contains $n$ integers, the elements of the array. \item Third line contains the integer \texttt{target}. \end{itemize} \outputformat \begin{itemize} \item Print two integers, the indices of the elements adding up to \texttt{target}. \end{itemize} \examples \begin{verbatim} Input: 4 2 7 11 15 9 Output: 0 1 \end{verbatim} % ========================= Problem 2 ========================= \problem{Problem 2: Longest Substring Without Repeating Characters} \textit{Difficulty: Medium} Given a string \texttt{s}, find the length of the longest substring without repeating characters. \inputformat \begin{itemize} \item A single line containing the string \texttt{s} ($1 \leq |s| \leq 10^5$). \end{itemize} \outputformat \begin{itemize} \item A single integer, the length of the longest substring without repeated characters. \end{itemize} \examples \begin{verbatim} Input: abcabcbb Output: 3 \end{verbatim} % ========================= Problem 3 ========================= \problem{Problem 3: Merge Intervals} \textit{Difficulty: Hard} Given a collection of intervals, merge all overlapping intervals. \inputformat \begin{itemize} \item First line contains an integer $n$ ($1 \leq n \leq 10^4$), the number of intervals. \item Next $n$ lines contain two integers each, representing the start and end of each interval. \end{itemize} \outputformat \begin{itemize} \item Print the merged intervals in ascending order of start times. \end{itemize} \examples \begin{verbatim} Input: 4 1 3 2 6 8 10 15 18 Output: 1 6 8 10 15 18 \end{verbatim} % ========================= Problem 4 ========================= \problem{Problem 3: Merge Intervals} \textit{Difficulty: Hard} \begin{itemize} You are given a string S composed of only the characters ‘6', ‘7’, ‘A', ‘B', and ‘\#' (without the quotation marks). This string is processed from left to right, and you must maintain a sequence of chracters that changes according to these rules: \item 6 - add a 6 to the end of the sequence \item 7 - if the sequence is non-empty and its last chracter is ‘6', remove that last ‘6', otherwise, add ‘7' to the end of the sequence \item A - reverse the sequence \item B - add a duplicate of the current sequence to the end of it \item \# - clear the sequence \end{itemize} \inputformat \begin{itemize} \item The first line consists of the string S. The string consists only of the characters 6, 7, A, B, and \#. \end{itemize} \outputformat \begin{itemize} \item Output a single line containig the final form of the sequence. If the sequence is empty at the end, output “EMPTY” (without the quotations). \end{itemize} \examples \begin{verbatim} Input 1: 67A6 Output 1: 6 Input 2: 66B7 Output 2: 666 Input 3: 7A7# Output 3: EMPTY \end{verbatim} \end{document}