Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a function to merge two sorted arrays into a single sorted array without duplicates.

Hard

Problem Statement

Write a function to merge two sorted arrays into a single sorted array without duplicates.

Sample Input

Two hardcoded arrays, e.g., [1, 3, 5] and [2, 3, 6].

Sample Output

Merged array: [1, 2, 3, 5, 6]

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
fun mergeAndRemoveDuplicates(arr1: Array<Int>, arr2: Array<Int>): List<Int> { return (arr1 + arr2).toSet().sorted() } fun main() { val arr1 = arrayOf(1, 3, 5) val arr2 = arrayOf(2, 3, 6) println("Merged array: ${mergeAndRemoveDuplicates(arr1, arr2)}") }
Log in or sign up to run or submit your code.Log inSign up
Input
Two hardcoded arrays, e.g., [1, 3, 5] and [2, 3, 6].
Expected Output
Merged array: [1, 2, 3, 5, 6]