Interview Questions and Answers
All Interview Questions and Answers
Shell Script Questions
1. Find Second Largest and Second Smallest and Add
arr=(12 13 3 4 1 6 9 17 13)
unique_arr=($(echo "${arr[@]}" | tr ' ' '\n' | sort -n | uniq))
second_smallest=${unique_arr[1]}
second_largest=${unique_arr[-2]}
sum=$((second_smallest + second_largest))
echo "Sum: $sum"
2. Reverse a String
reverseStr() {
local str="$1"
echo "$str" | rev
}
doTestsPass() {
local result=0
if [[ "$(reverseStr 'abcd')" == "dcba" ]]; then result=$((result + 1)); fi
if [[ "$(reverseStr 'odd abcde')" == "edcba ddo" ]]; then result=$((result + 1)); fi
if [[ "$(reverseStr 'even abcde')" == "edcba neve" ]]; then result=$((result + 1)); fi
if [[ "$(reverseStr "$(reverseStr 'no change')")" == "no change" ]]; then result=$((result + 1)); fi
if [[ "$(reverseStr '')" == "" ]]; then result=$((result + 1)); fi
if [[ $result -eq 5 ]]; then
echo "All tests pass"
else
echo "There are test failures"
fi
}
doTestsPass
3. Find Unique Characters and Print Longest Possible Substring
input="tisishatrecupttt"
declare -A freq
for ((i=0; i<${#input}; i++)); do
char="${input:$i:1}"
freq[$char]=$(( ${freq[$char]} + 1 ))
done
unique=""
for c in $(echo ${!freq[@]}); do
if [[ ${freq[$c]} -eq 1 ]]; then
unique+=$c
fi
done
echo "Unique characters substring: $unique"
4. Print Line 50 to 60 of a File
sed -n '50,60p' filename.txt
5. Search Pattern and Count Frequency
grep -o 'pattern' filename.txt | wc -l
6. Shell Script: Palindrome Check
str="$1"
rev_str=$(echo "$str" | rev)
if [[ "$str" == "$rev_str" ]]; then
echo "Palindrome"
else
echo "Not Palindrome"
fi
7. Check File Exists and Size and Send Email
if [[ -f "$file" ]]; then
if [[ $(stat -c%s "$file") -gt 0 ]]; then
echo "File exists and not empty" | mail -s "File Alert" user@example.com
fi
fi
8. Delete Blank Lines in a File
sed -i '/^$/d' filename.txt
9. AWK: Print Lines Greater Than Length 5
awk 'length($0) > 5' filename.txt
10. Print Last 10 Lines
tail -n 10 filename.txt
AutoSys Related Questions
On Hold vs On Ice
- On Hold: Job will not run until manually released. Successor jobs do not run.
- On Ice: Job will not run but successors can run as if it succeeded.
JIL File
Job Information Language (JIL) is used to define AutoSys jobs with attributes such as command, machine, owner, start times, etc.
Predecessor/Successor Concept
Predecessor: Job that must finish before another can start.
Successor: Job that depends on the predecessor.
Job Schedule
Defined using "start_times", "days_of_week", "run_calendar" attributes in AutoSys.
Java and Python Coding
1. Find Odd and Even Numbers
int[] arr = {2, 3, 4, 5, 6, 3, 7};
for (int num : arr) {
if (num % 2 == 0) System.out.println(num + " Even");
else System.out.println(num + " Odd");
}
2. Kill Process Problem
Map<Integer, List<Integer>> tree = new HashMap<>();
for (int i = 0; i < ppid.length; i++) {
tree.computeIfAbsent(ppid[i], k -> new ArrayList<>()).add(pid[i]);
}
Queue<Integer> queue = new LinkedList<>();
queue.add(kill);
while (!queue.isEmpty()) {
int current = queue.poll();
result.add(current);
if (tree.containsKey(current)) {
queue.addAll(tree.get(current));
}
}
3. Find Frequency of Characters
String s = "abcdascgab";
Map<Character, Integer> freq = new HashMap<>();
for (char c : s.toCharArray()) {
freq.put(c, freq.getOrDefault(c, 0) + 1);
}
4. Remove Lines with Null 6th Field
BufferedReader reader = new BufferedReader(new FileReader("input.txt"));
BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt"));
String line;
while ((line = reader.readLine()) != null) {
String[] fields = line.split(",");
if (fields.length >= 6 && fields[5] != null && !fields[5].isEmpty()) {
writer.write(line);
writer.newLine();
}
}
reader.close();
writer.close();
Conceptual Questions
Git
- Rebase: Reapply commits on top of another branch.
- Merge Conflict: Happens when two branches changed same line; resolve manually and commit.
Unix
- AWK: Text processing and extraction tool.
- Extract 20th line:
sed -n '20p' filename.txt
SDLC Process
Phases: Planning, Analysis, Design, Development, Testing, Deployment, Maintenance.
CI/CD Pipeline
Build - Test - Deploy automatically on code changes using tools like Jenkins, GitHub Actions, etc.
Logical Questions
1. Dot Product of Two Arrays
int[] a = {1, 2, 3};
int[] b = {4, 5, 6};
int result = 0;
for (int i = 0; i < a.length; i++) result += a[i] * b[i];
2. Print Integers from String
String input = "a1b2c3";
for (char c : input.toCharArray()) {
if (Character.isDigit(c)) System.out.print(c + " ");
}
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment