library.js ( ***REVISE***)

 /* Library Problem

Inputs:-

no of books = 12

booklist:-
wings of fire
2 states
rich dad vs poor dad
godan
ramayana
you can win
pride and prejudice
without fear
diary of a young girl
malgudi days
bhagvat gita
will you still love me?

no of queries = 3

query list:-
bhagvat gita
the joy of achievement
godan

output:-
Available
Not Available
Available

*/

let fs = require("fs");

let data = fs.readFileSync(0, 'utf-8');
let idx = 0;
data = data.split('\n');

function readLine() {
idx++;
return data[idx - 1].trim();
}

const noOfBooks = parseInt(readLine()); // 12

const bookList = [] // initializing with an empty array

for (let i = 0; i < noOfBooks; i++) {

bookList.push(readLine()); // read each input and push it in the array
}

//console.log(bookList);

const noOfQuery = parseInt(readLine()); // 3

const queryList = [] //initializing with an empty array

for (let i = 0; i < noOfQuery; i++) {

queryList.push(readLine()); //read each input and push it in the array

}

//console.log(queryList);

for (let i = 0; i < noOfQuery; i++) {

const actualQuery = queryList[i];

let mark = false; // we are assuming initially no query is present in the list

for (let j = 0; j < noOfBooks; j++) {

if (actualQuery == bookList[j]) {
console.log(actualQuery, 'is Available');
mark = true;
break;
}
}
if (mark == false) {
console.log(actualQuery, ' is not Available');
}
}

===============================================================================================
TERMINAL:










Comments