Confusion Matrix Analysis
Confusion Matrix Analysis
Which metric is best to analyze true positives, false positives, false negatives, and true
negatives?
R-squared
ROC Curve
Confusion Matrix
Accuracy
f = open('file.txt','r')
print(f.readline())
Error
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 1/27
Import numpy as np
n1= [[1, 2], [4, 5]] n2 = [[6, 7], [9, 3]] prod = np.dot(n1, n2)
print(prod)
[[69,43]
[24 13]]
[[24 13 69 43]]
[[24 13]
[6943]]
We have:
python
import numpy as np
print(prod)
Matrix multiplication:
1 2 6 7
n1 = [ ], n2 = [ ]
4 5 9 3
Result:
24 13
[ ]
69 43
Copies myList
Reverses myList
mylist [1.2.3
myList(1) 4
print(myList)
(14.3
[4.2.3)
[123]
Error
Your code seems to have syntax errors as written, but if we interpret it correctly as:
python
myList = [1, 2, 3]
myList[1] = 4
print(myList)
Explanation:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 3/27
✅ Correct answer: [1, 4, 3]
Question-4
Mary for
What will be the correct output of the given code snippet? "import pandas as pd fruit =
pd.Series(['Mango', 'Apple']) color - [Yellow', 'Red'] df = pd.DataFrame(colour, index fruit,
columns=['Color']) print(df)
04
10
Color
Apple Red
Mango Yellow
Mango Color
Apple Red
Yellow
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 4/27
Color
Mango Yellow
Apple Red
Let’s break it down carefully — the provided code has small typos, so I’ll rewrite it in a valid form:
python
import pandas as pd
Step-by-step:
fruit is a Series:
vbnet
0 Mango
1 Apple
dtype: object
color is a list:
css
['Yellow', 'Red']
mathematica
Color
Mango Yellow
Apple Red
SOL query
JSON file
Random associations
Unrelated content
In Lang Chain, which combination is commonly used in retrieval chains for RAG systems?
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 6/27
Retriever Agent OutputParser
Retriever+LLM+Prompt Template
Prompt Template → structures how the context and query are passed to the LLM.
Question-10
DM
The correct answer is: To allow concurrent I/O operations like API calls or DB queries ✅
In FastAPI, declaring an endpoint with async def is beneficial when your code performs I/O-bound tasks
(e.g., database queries, external API requests, file reads) so other requests can be handled while waiting
for these operations to complete.
Content-Type
Access-Control-Allow-Origin
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 7/27
Cache-Control
Authorization
def example():
return 5+5
None
5+5
OD
10
What will be the correct output of the following code? "Import numpy as np a = np.array([[4, 3],
[4, 6]]) b = np.array([[1,2], [4, 5]]) c = np.sum(a - b)
print(c)
29
[[55]
[811]]
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 8/27
[[10]. [19]]
python
import numpy as np
print(c)
4−1 3−2 3 1
a−b=[ ]=[ ]
4−4 6−5 0 1
3+1+0+1=5
✅ Correct output: 5
Since 5 is not in your listed options, the right choice here is None of the above.
import numpy as np
print(c)
4+1 3+2 5 5
a+b=[ ]=[ ]
4+4 6+5 8 11
5 + 5 + 8 + 11 = 29
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 9/27
✅ Output: 29
The correct answer is: Precision and recall are both important ✅
The F1 Score is the harmonic mean of precision and recall, making it especially useful when you need a
balance between the two — particularly in cases with imbalanced classes.
No-difference
Which of the following limits the length of output tokens from OpenAI APIs, potentially
truncating long responses?
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 10/27
temperature
top p
frequency penalty
max tokens
d = {'a': 1, 'b': 2}
No error
Question-23
DMark
Why are Approximate Nearest Neighbor (ANN) algorithms preferred over exact searches in
vector databases?
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 11/27
They provide perfect accuracy
They significantly improve speed in high-dimensional spaces with acceptable accuracy tradeoffs
The correct answer is: They significantly improve speed in high-dimensional spaces with acceptable
accuracy tradeoffs ✅
Approximate Nearest Neighbor (ANN) algorithms trade a small amount of accuracy for much faster
search times in large, high-dimensional vector databases, making them ideal for embeddings-based
retrieval.
Sentence segmentation
Text understanding
Data cleaning
Data aggregation
Data enrichment
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 12/27
The correct answer is: Data extraction from APIs ✅
Reason:
Transform phase involves tasks like data cleaning, aggregation, and enrichment.
Data extraction from APIs happens in the Extract phase, not in Transform.
Removing regularization
Which of the following plots is best suited to understand distribution of a single numerical
variable?
Line chart
Bar chart
Histogram
Scatter plot
What will be the correct output of the given code snippet? "import numpy as np print(np.fuil
(1.2), 5))"
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 13/27
Select one correct answer from the following
[1.2.3.4.5]
[5.5.5,5,5)
[[55]]
The code in your question seems to have a small typo, so I’ll rewrite it correctly:
python
import numpy as np
print(np.full((1, 2), 5))
Explanation:
np.full((1, 2), 5) creates a NumPy array of shape (1, 2) filled with the value 5.
Shape (1, 2) means 1 row, 2 columns.
Output:
lua
[[5 5]]
The correct answer is: Lists use more memory than tuples ✅
Reason:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 14/27
Lists are mutable, so Python allocates extra memory to accommodate changes (adding/removing
elements).
Tuples are immutable, so they need less memory since their size is fixed once created.
Sam and Alex are competitive coders who enjoy creating string challenges for each other. In
one such challenge, Sam asks Alex to write a function that sorts a string according to specific
rules.
1. Start by appending the smallest character from the original string s to ss.
2. From the remaining characters, append the next smallest character that is greater than the
last appended character.
3. Repeat step 2 until no more valid characters can be added (ie., no greater characters remain).
4. Then, start appending the largest character that is less than the last character added.
5. Repeat step 4 until no more valid characters can be added (ie, no smaller characters remain).
6. If the remaining characters are all the same and none satisfy the conditions in steps 2-5, pick
any one of them and add it to ss.
7. Repeat steps 2-6 until all characters from the original string s have been used.
Input Format
Constraints:
1≤s≤ 10^5
Example
sababyz
ababyz a a
<- step 1
babyz b
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 15/27
ab
<- step 2
abyz y
aby
abz z
abyz
ab
Returns
You must write a complete program, starting from the main function. Your program should
read input from standard input and write the result to standard output.
Sample input:
ababyz
Sample output:
abyzba
Got it — this is essentially a custom sorting simulation problem, similar to LeetCode’s “Increasing
Decreasing String” (1370).
We’ll solve it step-by-step:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 16/27
Plan
1. Count the frequency of each character (since we’ll need to know how many remain).
Code:
python
def main():
s = input().strip()
result = []
while len(result) < len(s):
# Step 1 & 2: Append smallest -> largest (ascending order)
for ch in sorted(freq.keys()):
if freq[ch] > 0:
result.append(ch)
freq[ch] -= 1
print("".join(result))
if __name__ == "__main__":
main()
Example Run:
Input:
nginx
ababyz
Process:
makefile
Ascending: a b y z
Descending: b a
Output:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 17/27
nginx
abyzba
This runs in O(n log k) where k ≤ 26, which is efficient for n ≤ 10^5.
Do you want me to also optimize it to O(n) by avoiding sorting in every loop? That would make it even
faster for large inputs.
Python 3.6
Got it — for Python 3.6, we can still implement it the same way, but to make it faster and avoid sorting
on every loop, we’ll just iterate over the alphabet string 'abcdefghijklmnopqrstuvwxyz' and its reverse
once per pass.
Here’s the optimized Python 3.6 version:
python
def main():
s = input().strip()
result = []
total_len = len(s)
alphabet = 'abcdefghijklmnopqrstuvwxyz'
# Descending order
for ch in reversed(alphabet):
if freq[ch] > 0:
result.append(ch)
freq[ch] -= 1
print("".join(result))
if __name__ == "__main__":
main()
Example run:
makefile
Input:
ababyz
Output:
abyzba
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 18/27
✅ Works in Python 3.6, avoids repeated sorting, runs in O(n).
If you want, I can also simulate the exact “step-by-step” picking like in your example table. That would
show how it builds the string at each stage.
Traceback (most recent call last): File "script-3.6.0.py", line 1, in <module> userinput =
input().strip() EOFError: EOF when reading a line
That EOFError happens because your Python environment is running the script without actually
passing any input to input().
In a normal terminal, you’d run it like:
bash
python script.py
ababyz
But in online judges or certain IDEs, you may need to handle no input gracefully.
We can fix it by wrapping input() in a try-except block:
python
def main():
import sys
from collections import Counter
try:
s = input().strip()
except EOFError:
# No input provided
return
freq = Counter(s)
result = []
total_len = len(s)
alphabet = 'abcdefghijklmnopqrstuvwxyz'
# Descending order
for ch in reversed(alphabet):
if freq[ch] > 0:
result.append(ch)
freq[ch] -= 1
print("".join(result))
if __name__ == "__main__":
main()
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 19/27
If the environment sends no input, EOFError is caught, and the program ends without crashing.
If input is given, it runs normally.
Do you want me to also rewrite it so you can test it without typing input (by hardcoding s) while
developing? That would avoid the EOF issue in your test environment.
Coding 03
A manufacturing facility uses a milling machine equipped with a circular tool changer that holds
n tools. These tools are arranged in a circular array and may include duplicate names.
The machine operator can rotate the tool changer one position at a time, either to the left or to
the right, to bring the desired tool into position. After reaching the end of the array in either
direction, it wraps around to the other side (i.e., the array is circular).
Given:
A list of n tool names in the order they appear on the tool changer,
Your task is to calculate and print the minimum number of moves (either left or right) needed to
reach the nearest instance of the required tool.
You must read input from standard input and print output to standard output.
Input Format
The first line contains an integer n, the number of tools in the changer. The next n lines each
contain a string tools[i], the name of a tool at index i. The following line contains an integer
startIndex, representing the index of the currently active tool.
The last line contains a string target, the name of the required tool.
Constraints:
Constraints:
1 ≤ n ≤ 100
0s startindex ≤ n - 1
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 20/27
The target tool is guaranteed to be present in the list
Output Format
Print a single integer - the minimum number of moves required to reach the closest occurrence
of the target tool.
Customiinput
Output
Sample input:
"ballendmill
Sample output:
python
def main():
# Read inputs
n = int(input().strip())
tools = [input().strip() for _ in range(n)]
startIndex = int(input().strip())
target = input().strip()
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 21/27
counter_clockwise = n - clockwise
# Take the smaller
min_moves = min(min_moves, min(clockwise, counter_clockwise))
print(min_moves)
if __name__ == "__main__":
main()
Example Run:
Input:
4
ballendmill
keywaycutter
slotdrill
facemill
1
ballendmill
Output:
Why it works:
If you want, I can also make it accept array-like input like in your sample (['ballendmill',
'keywaycutter', ...]) directly instead of line-by-line. That would let you copy-paste sample inputs
exactly. Would you like me to do that?
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 22/27
Wraps input() in try-except
Lets you hardcode test values if no stdin is provided (useful for debugging in environments like
yours).
python
def main():
try:
# Read number of tools
n = int(input().strip())
tools = [input().strip() for _ in range(n)]
startIndex = int(input().strip())
target = input().strip()
except EOFError:
# Hardcoded fallback for testing without stdin
n = 4
tools = ["ballendmill", "keywaycutter", "slotdrill", "facemill"]
startIndex = 1
target = "ballendmill"
min_moves = n
for i, tool in enumerate(tools):
if tool == target:
clockwise = abs(i - startIndex)
counter_clockwise = n - clockwise
min_moves = min(min_moves, min(clockwise, counter_clockwise))
print(min_moves)
if __name__ == "__main__":
main()
4
ballendmill
keywaycutter
slotdrill
facemill
1
ballendmill
and output:
nginx
python script.py
4
ballendmill
keywaycutter
slotdrill
facemill
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 23/27
1
ballendmill
Do you want me to modify it so it parses the list directly from one line like your example
['ballendmill', 'keywaycutter', ...]? That would make it easier to paste test data.
Got it✅ — in an online proctored compiler you won’t be able to hardcode or skip input, you must read
exactly in the format the system sends.
From your problem statement, the input is not given in Python list form — the example ['ballendmill',
'keywaycutter', ...] in the text was just for illustration.
In the real test case, it will be given line by line like this:
4
ballendmill
keywaycutter
slotdrill
facemill
1
ballendmill
So your code should only use input() for reading exactly those lines and nothing else.
Here’s the clean submission-ready version (Python 3.6 compatible, no extra prints, no try-except):
python
def main():
n = int(input().strip())
tools = [input().strip() for _ in range(n)]
startIndex = int(input().strip())
target = input().strip()
min_moves = n
for i, tool in enumerate(tools):
if tool == target:
clockwise = abs(i - startIndex)
counter_clockwise = n - clockwise
min_moves = min(min_moves, min(clockwise, counter_clockwise))
print(min_moves)
if __name__ == "__main__":
main()
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 24/27
Do you want me to also prepare the Java version in case the online test asks for Java instead of Python?
That’s common in proctored coding rounds.
You are given a sentence consisting of words separated by spaces. Each word contains only
English letters (uppercase or lowercase).
Your task is to find and print the first word that has an even length and is the longest among all
even-length words in the sentence.
Input Format
Output Format
Example Input
Example Output
Time
Explanation
Their lengths: 4, 2, 5, 5, 4
"Time" and "code" are the longest even-length words (characters), but "Time""Time" and "code"
are the longest even-length words (characters), but "Time" appears first.
You must write a complete program, starting from the main function, that reads input from
standard input and prints the result to standard output.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 25/27
Sample input:
Sample output:
Pleasant
<Previous Question
Got it — you’re facing an EOFError because your online proctor compiler doesn’t actually provide input
interactively; it expects the code to just read whatever input is already there.
We can solve your problem with a simple input() read, process the sentence, and print the required
word.
Here’s a Python 3.6 compliant solution:
python
def main():
try:
sentence = input().strip()
except EOFError:
sentence = ""
words = sentence.split()
longest_word = ""
max_length = 0
if max_length > 0:
print(longest_word)
else:
print("00")
if __name__ == "__main__":
main()
How it works:
✅ This will pass in online compilers where input is provided in one go.
If you want, I can also give you an optimized version for O(n) traversal that doesn’t store all words in
memory — better for 10^5 length constraints.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 26/27
Would you like me to prepare that?
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 27/27