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

Programming Exercises

Write a function to replace NA values in a vector with the median of the non-NA values.

Medium

Problem Statement

Write a function to replace NA values in a vector with the median of the non-NA values.

Sample Input

Vector: c(10, 20, NA, 40, 50)

Sample Output

Replaced Vector: 10 20 30 40 50

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
# Predefined structure replace_na_with_median <- function(vector) { # Your logic here } result <- replace_na_with_median(vector) print(paste("Replaced Vector:", result))
Log in or sign up to run or submit your code.Log inSign up
Input
Vector: c(10, 20, NA, 40, 50)
Expected Output
Replaced Vector: 10 20 30 40 50