how to fix Round 2 Semi-Final TechGig Code Gladiator 2022
Movie Theater:
Reena is a movie enthusiast and loves to see movies in theaters. A new movie is releasing this Friday and Reena wants to watch it. Her favorite theater is witnessing a large crowd but she wants to watch the film in that theater only. Reena has her favorite seats in the theater and will watch the movie only if her selected seat is vacant.
The theater has S seats and T tickets have already been sold. There are Q seats which are liked by Reena in that theater. Reena is very busy with her modeling project and needs your help in determining if her favorite seat is vacant or not. She will provide you with all the details regarding the number of seats in the theater and the seats already allotted. Can you help her figure out if her favorite seat in the theater is vacant or not? If her favorite seat is occupied, represent the status of that seat with N; else the status of that seat will be Y representing the seat is vacant.
Example: 4 seats are already occupied, T = 4 Reena likes 3 seats, Q = 3 Seats Reena like are, 1, 2 and 6 Seat 1: It is already occupied by someone so Reena will get N as value. Seat 2: This seat is empty so Reena will get Y as value and she can book this seat and watch the movie. Seat 6: This seat is also preoccupied so Reena will get N as value.Input Format:
- The first line of input consists of three space-separated integers, S, T and Q respectively.
- Next T lines each will consist of an integer representing the occupied seat.
- Next Q lines each will consist of an integer representing the preferred seats of Reena in the theater.
Constraints :
1<= S <=10^9 (1e9)
0<= T <=10^6
0<= Q <=10^6
The occupied seat and preferred seat will range from 1 to N
(both inclusive).
Note: Read the input from the console.
Output Format:
For each preferred seat of Reena, print it's status (N - Occupied, Y - Vacant) in a separate line.
Sample - TestCase 1Input:
6 4 4
1
3
4
6
1
2
5
6
Output:
N
Y
Y
N
Explanation The occupied seats are the same as the example.
Occupied seats:
1, 3, 4 and 6
Preferred Seats: 1, 2, 5 and 6
Seat 1:
Already Occupied, Status = N
Seat 2:
Vacant, Status = Y
Seat 5:
Vacant, Status = Y
Seat 6:
Already Occupied, Status = N
Time Limit(X): 0.50 sec(s) for each input.
Memory Limit: 512 MB
Source Limit: 100 KB
Allowed Languages:
C, C++, C++11, C++14, C#, Java, Java 8, Kotlin, PHP, PHP 7,
Python, Python 3, Perl, Ruby, Node Js, Scala, Clojure, Haskell,
Lua, Erlang, Swift, VBnet, Js, Objc, Pascal, Go, F#, D, Groovy,
Tcl, Ocaml, Smalltalk, Cobol, Racket, Bash, GNU Octave, Rust,
Common LISP, R, Julia, Fortran, Ada, Prolog, Icon, Elixir,
CoffeeScript, Brainfuck, Pypy, Lolcode, Nim, Picolisp, Pike,
pypy3
Solution code
/* Read input from STDIN. Print your output to STDOUT*/
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *a[])
{
//Write code here
long long int S,T,Q;
cin>>S>>T>>Q;
unordered_set<long long int> tickets;
long long int temp,i;
for( i = 0; i< T; i++){
cin>>temp;
tickets.insert(temp);
}
for( i = 0; i< Q; i++){
cin>>temp;
if(tickets.find(temp) != tickets.end()){
cout<<"N"<<endl;
}
else{
cout<<"Y"<<endl;
}
}
}
0 Comments
If you have any doubts or any topics that you want to know more about them please let me know