Top 30 Playwright TypeScript Programs
Most Asked Coding Challenges in SDET Technical Interviews
Want to Practice on a Live Sandbox?
Over 1,000+ SDETs practice daily inside our built-in browser compiler to test algorithms and crack top automation engineering interviews.
SDET Coding Challenge Directory
Coding tests are a standard filter in any Senior SDET or Test Architect interview. Below is the curated compilation of the Top 30 Coding Challenges asked in modern Playwright / TypeScript automation technical interviews.
1.Reverse a String
TSReverses a string by iterating backwards from the last character and appending each character to a result string.
function reverse(s: string) { let res = ''; for(let i = s.length-1; i >= 0; i--) res += s[i]; return res; }
2.Check Palindrome
TSChecks if a string reads the same forwards and backwards using a two-pointer approach comparing characters from outer ends inward.
function isPalindrome(s: string) { let l = 0, r = s.length-1; while(l < r) { if(s[l++] !== s[r--]) return false; } return true; }
3.First Unique Character
TSFinds the first character in a string that does not repeat. Uses a frequency map to count occurrences, then scans the string to find the first character with a count of 1.
function firstUniq(s: string) { const map: Record<string,number> = {}; for(const c of s) map[c] = (map[c]||0)+1; for(const c of s) { if(map[c] === 1) return c; } return null; }
4.Character Frequency
TSCounts the occurrence of each character in a string and returns a dictionary/object mapping characters to their counts.
function charFreq(s: string) { const map: Record<string,number> = {}; for(const c of s) { map[c] = (map[c]||0)+1; } return map; }
5.Remove Array Duplicates
TSRemoves duplicate values from an array using JavaScriptβs Set collection, which automatically filters out duplicate elements.
function removeDups(arr: number[]) { return Array.from(new Set(arr)); }
6.Check Anagram
TSDetermines if two strings are anagrams by sorting their characters and comparing the resulting strings for equality.
function isAnagram(s1: string, s2: string) { if(s1.length !== s2.length) return false; const norm = (s: string) => s.split('').sort().join(''); return norm(s1) === norm(s2); }
7.Bubble Sort
TSA simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.
function bubbleSort(arr: number[]) { for(let i=0; i<arr.length-1; 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]]; } } } return arr; }
8.Selection Sort
TSSorts an array by repeatedly finding the minimum element from the unsorted part and putting it at the beginning.
function selectSort(arr: number[]) { for(let i=0; i<arr.length-1; i++) { let min = i; for(let j=i+1; j<arr.length; j++) if(arr[j] < arr[min]) min = j; [arr[i], arr[min]] = [arr[min], arr[i]]; } return arr; }
9.Second Largest Number
TSFinds the second largest number in an array in a single pass by keeping track of the largest and second largest elements found so far.
function secondLarge(a: number[]) { let max = -Infinity, sec = -Infinity; for(const n of a) { if(n > max) { sec=max; max=n; } else if(n > sec && n !== max) sec=n; } return sec; }
10.Missing Number (1 to N)
TSFinds the single missing number in an array containing numbers from 1 to N using the arithmetic sum formula: Sum = N * (N + 1) / 2.
function missingNum(arr: number[], n: number) { const expSum = (n * (n + 1)) / 2; const actSum = arr.reduce((a,b)=>a+b,0); return expSum - actSum; }
11.Reverse Words in Sentence
TSReverses the order of words in a sentence by splitting the string by whitespace, reversing the array of words, and joining them back.
function revWords(s: string) { return s.trim().split(/\s+/).reverse().join(' '); }
12.Roman to Integer
TSConverts a Roman numeral string into its integer equivalent by scanning the string and subtracting values when a smaller numeral precedes a larger one.
function romanToInt(s: string) { const map: any = { I:1, V:5, X:10, L:50 }; let tot = 0; for(let i=0; i<s.length; i++) { if(map[s[i]] < map[s[i+1]]) tot -= map[s[i]]; else tot += map[s[i]]; } return tot; }
13.Merge Sorted Arrays
TSMerges two already sorted arrays into a single sorted array using a two-pointer technique for optimal linear time complexity.
function mergeArr(a: number[], b: number[]) { let res = [], i=0, j=0; while(i < a.length && j < b.length) res.push(a[i] <= b[j] ? a[i++] : b[j++]); return [...res, ...a.slice(i), ...b.slice(j)]; }
14.Binary Search O(log N)
TSFinds the index of a target value in a sorted array by repeatedly dividing the search interval in half.
function binSearch(a: number[], t: number) { let l = 0, r = a.length-1; while(l <= r) { let m = Math.floor((l+r)/2); if(a[m] === t) return m; a[m] < t ? l=m+1 : r=m-1; } return -1; }
15.FizzBuzz
TSPrints numbers from 1 to N, but prints "Fizz" for multiples of 3, "Buzz" for multiples of 5, and "FizzBuzz" for multiples of both.
function fizzBuzz(n: number) { for(let i=1; i<=n; i++) { let out = ''; if(i%3===0) out += 'Fizz'; if(i%5===0) out += 'Buzz'; console.log(out || i); } }
16.Fibonacci (Memoized)
TSCalculates the N-th Fibonacci number efficiently using recursion combined with memoization (caching intermediate results) to prevent exponential runtime.
const memo: Record<number,number> = {}; function fib(n: number): number { if(n <= 1) return n; if(memo[n]) return memo[n]; return memo[n] = fib(n-1) + fib(n-2); }
17.Factorial (Recursive)
TSComputes the factorial of a number N using standard mathematical recursion.
function factorial(n: number): number { if (n === 0 || n === 1) return 1; return n * factorial(n - 1); }
18.Two Sum O(N)
TSFinds the indices of two numbers in an array that add up to a specific target value, using a Map to store indices of visited numbers for lookups.
function twoSum(a: number[], t: number) { const map = new Map(); for(let i=0; i<a.length; i++) { const comp = t - a[i]; if(map.has(comp)) return [map.get(comp), i]; map.set(a[i], i); } return []; }
19.Max Subarray (Kadane)
TSFinds the contiguous subarray within a one-dimensional array of numbers which has the largest sum using Kadaneβs dynamic programming algorithm.
function maxSubArray(nums: number[]) { let curr = nums[0], max = nums[0]; for(let i=1; i<nums.length; i++) { curr = Math.max(nums[i], curr + nums[i]); max = Math.max(max, curr); } return max; }
20.Valid Parentheses
TSChecks if a string of braces and brackets is valid by matching opening and closing characters using a stack data structure.
function isValid(s: string) { const stack = [], map: any = { ')':'(', '}':'{' }; for(const c of s) { if(!map[c]) stack.push(c); else if(stack.pop() !== map[c]) return false; } return stack.length === 0; }
21.Check Prime Number
TSDetermines if a number N is prime by checking divisibility up to the square root of N.
function isPrime(n: number) { if(n <= 1) return false; for(let i = 2; i <= Math.sqrt(n); i++) if(n % i === 0) return false; return true; }
22.Count Vowels
TSCounts the number of vowels (a, e, i, o, u) in a string using a predefined Set for efficient constant-time checks.
function countVowels(s: string) { const vowels = new Set(['a','e','i','o','u']); let count = 0; for(const c of s.toLowerCase()) { if(vowels.has(c)) count++; } return count; }
23.Array Intersection
TSFinds the common elements between two arrays by converting one array into a Set and filtering the second array.
function intersection(a: number[], b: number[]) { const setA = new Set(a); return b.filter(x => setA.has(x)); }
24.Sum of Array Elements
TSComputes the total sum of all elements in an array using JavaScriptβs native Array.prototype.reduce helper.
function arraySum(arr: number[]) { return arr.reduce((acc, curr) => acc + curr, 0); }
25.Find Maximum Element
TSFinds the largest number in an array using Math.max combined with ES6 spread operator.
function findMax(arr: number[]) { return Math.max(...arr); }
26.Reverse Array In-Place
TSReverses the elements of an array in-place without allocating extra memory by swapping values from the outer boundaries moving inward.
function reverseArray(arr: any[]) { let l = 0, r = arr.length - 1; while (l < r) { [arr[l], arr[r]] = [arr[r], arr[l]]; l++; r--; } return arr; }
27.Find All Duplicates
TSFinds all elements that appear more than once in an array using sets to keep track of seen and duplicate values.
function findDuplicates(arr: number[]) { const seen = new Set(), dups = new Set(); for (const n of arr) { if(seen.has(n)) dups.add(n); seen.add(n); } return Array.from(dups); }
28.Capitalize First Letters
TSCapitalizes the first letter of each word in a string/sentence by splitting, mapping, and joining.
function capitalize(s: string) { return s.split(' ') .map(w => w[0].toUpperCase() + w.slice(1)) .join(' '); }
29.Check Substring
TSValidates if a specific substring exists inside a parent string using JavaScriptβs native indexOf helper.
function containsSub(s: string, sub: string) { return s.indexOf(sub) !== -1; }
30.Flatten Nested Array
TSFlattens an array with arbitrary nested arrays into a single flat array using recursive reduction.
function flatten(arr: any[]): any[] { return arr.reduce((acc, val) => Array.isArray(val) ? acc.concat(flatten(val)) : acc.concat(val) , []); }
Have a specific question? Ask our AI Coach!
Explore custom roadmaps, ask technical questions, and design your QA and AI interview preparation path.