Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views1 page

Coding Test Questions

The document contains coding practice questions and solutions in Python and JavaScript, covering various topics such as array traversal, finding minimum and maximum values, reversing arrays, checking for palindromes, counting vowels, linear and binary search, and bubble sort. Each question is accompanied by sample code snippets in both programming languages. This serves as a resource for practicing fundamental coding concepts.

Uploaded by

Ketan Sutar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Coding Test Questions

The document contains coding practice questions and solutions in Python and JavaScript, covering various topics such as array traversal, finding minimum and maximum values, reversing arrays, checking for palindromes, counting vowels, linear and binary search, and bubble sort. Each question is accompanied by sample code snippets in both programming languages. This serves as a resource for practicing fundamental coding concepts.

Uploaded by

Ketan Sutar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Coding Practice Questions (Python & JavaScript)

1. Array Traversal
Q: Write a program to traverse an array and print all elements.
Python:
arr = [10, 20, 30, 40, 50] for i in arr: print(i) JavaScript:
let arr = [10, 20, 30, 40, 50]; arr.forEach(e => console.log(e));
2. Find Minimum and Maximum in Array
Q: Write a program to find min and max in an array.
Python:
arr = [12, 45, 2, 19, 8] print("Min:", min(arr)) print("Max:", max(arr)) JavaScript:
let arr = [12, 45, 2, 19, 8]; console.log("Min:", Math.min(...arr)); console.log("Max:",
Math.max(...arr));
3. Reverse an Array
Python:
arr = [1, 2, 3, 4, 5] print(arr[::-1]) JavaScript:
let arr = [1, 2, 3, 4, 5]; console.log(arr.reverse());
4. Palindrome String
Q: Check if a string is palindrome.
Python:
s = "madam" print(s == s[::-1]) JavaScript:
let s = "madam"; console.log(s === s.split("").reverse().join(""));
5. Count Vowels in String
Python:
s = "hello world" count = sum(1 for ch in s if ch in "aeiouAEIOU") print("Vowels:", count) JavaScript:
let s = "hello world"; let count = s.split("").filter(ch => "aeiouAEIOU".includes(ch)).length;
console.log("Vowels:", count);
6. Linear Search
Python:
arr = [10, 20, 30, 40, 50] x = 30 found = -1 for i in range(len(arr)): if arr[i] == x: found = i break
print("Found at index:", found) JavaScript:
let arr = [10, 20, 30, 40, 50]; let x = 30; let idx = arr.indexOf(x); console.log("Found at index:", idx);
7. Binary Search (sorted array)
Python:
def binary_search(arr, x): low, high = 0, len(arr) - 1 while low <= high: mid = (low + high) // 2 if
arr[mid] == x: return mid elif arr[mid] < x: low = mid + 1 else: high = mid - 1 return -1
print(binary_search([10, 20, 30, 40, 50], 30)) JavaScript:
function binarySearch(arr, x) { let low = 0, high = arr.length - 1; while (low <= high) { let mid =
Math.floor((low + high) / 2); if (arr[mid] === x) return mid; else if (arr[mid] < x) low = mid + 1; else
high = mid - 1; } return -1; } console.log(binarySearch([10,20,30,40,50], 30));
8. Bubble Sort
Python:
arr = [64, 25, 12, 22, 11] n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j],
arr[j+1] = arr[j+1], arr[j] print(arr) JavaScript:
let arr = [64, 25, 12, 22, 11]; for (let i = 0; i < arr.length; i++) { for (let j = 0; j < arr.length - i - 1; j++) { if
(arr[j] > arr[j+1]) { [arr[j], arr[j+1]] = [arr[j+1], arr[j]]; } } } console.log(arr);

You might also like