
Practice 50 Kotlin Lambda Expression Coding Questions
Q1. Write a Kotlin program to create a simple lambda expression that adds two numbers.
Input: a = 3, b = 4
Expected Output: 7
Q2. Write a Kotlin program to filter even numbers from a list using a lambda expression.
Input: numbers = [1, 2, 3, 4, 5]
Expected Output: [2, 4]
Q3. Write a Kotlin program to sort a list of numbers in descending order using a lambda expression.
Input: numbers = [5, 1, 3, 2, 4]
Expected Output: [5, 4, 3, 2, 1]
Q4. Write a Kotlin program to find the square of a number using a lambda expression.
Input: num = 5
Expected Output: 25
Q5. Write a Kotlin program to map each number in a list to its square using a lambda expression.
Input: numbers = [1, 2, 3]
Expected Output: [1, 4, 9]
Q6. Write a Kotlin program to sum all elements in a list using a lambda expression.
Input: numbers = [1, 2, 3, 4]
Expected Output: 10
Q7. Write a Kotlin program to find the maximum value in a list using a lambda expression.
Input: numbers = [1, 2, 3, 4]
Expected Output: 4
Q8. Write a Kotlin program to check if all elements in a list are greater than a given number using a lambda expression.
Input: numbers = [5, 6, 7], threshold = 4
Expected Output: true
Q9. Write a Kotlin program to find the sum of squares of all elements in a list using a lambda expression.
Input: numbers = [1, 2, 3]
Expected Output: 14
Q10. Write a Kotlin program to convert a list of integers to a list of strings using a lambda expression.
Input: numbers = [1, 2, 3]
Expected Output: ["1", "2", "3"]
Q11. Write a Kotlin program to filter out numbers that are divisible by 3 using a lambda expression.
Input: numbers = [1, 2, 3, 4, 5, 6]
Expected Output: [3, 6]
Q12. Write a Kotlin program to calculate the length of each string in a list using a lambda expression.
Input: strings = ["Kotlin", "Lambda", "Expression"]
Expected Output: [6, 6, 10]
Q13. Write a Kotlin program to reverse a list of integers using a lambda expression.
Input: numbers = [1, 2, 3, 4]
Expected Output: [4, 3, 2, 1]
Q14. Write a Kotlin program to multiply each number in a list by 2 using a lambda expression.
Input: numbers = [1, 2, 3]
Expected Output: [2, 4, 6]
Q15. Write a Kotlin program to find the first even number in a list using a lambda expression.
Input: numbers = [1, 3, 5, 4, 6]
Expected Output: 4
Q16. Write a Kotlin program to filter strings that contain the letter "a" using a lambda expression.
Input: strings = ["Kotlin", "Java", "Python"]
Expected Output: ["Kotlin", "Java"]
Q17. Write a Kotlin program to create a lambda expression that multiplies two numbers.
Input: a = 3, b = 4
Expected Output: 12
Q18. Write a Kotlin program to find the average of numbers in a list using a lambda expression.
Input: numbers = [1, 2, 3, 4, 5]
Expected Output: 3.0
Q19. Write a Kotlin program to check if any element in a list is negative using a lambda expression.
Input: numbers = [1, -2, 3, 4]
Expected Output: true
Q20. Write a Kotlin program to find the first string in a list that starts with "K" using a lambda expression.
Input: strings = ["Kotlin", "Java", "JavaScript"]
Expected Output: "Kotlin"
Q21. Write a Kotlin program to remove null values from a list using a lambda expression.
Input: values = [1, null, 2, null, 3]
Expected Output: [1, 2, 3]
Q22. Write a Kotlin program to check if any string in a list has a length greater than 5 using a lambda expression.
Input: strings = ["Kotlin", "Java", "Python"]
Expected Output: true
Q23. Write a Kotlin program to create a lambda expression that divides two numbers.
Input: a = 10, b = 2
Expected Output: 5
Q24. Write a Kotlin program to sort a list of strings in ascending order using a lambda expression.
Input: strings = ["banana", "apple", "cherry"]
Expected Output: ["apple", "banana", "cherry"]
Q25. Write a Kotlin program to find the number of elements in a list that are greater than 5 using a lambda expression.
Input: numbers = [1, 2, 6, 4, 8]
Expected Output: 2
Q26. Write a Kotlin program to find the product of all elements in a list using a lambda expression.
Input: numbers = [2, 3, 4]
Expected Output: 24
Q27. Write a Kotlin program to create a lambda expression that returns the maximum of two numbers.
Input: a = 7, b = 5
Expected Output: 7
Q28. Write a Kotlin program to check if all strings in a list contain more than 3 characters using a lambda expression.
Input: strings = ["Kotlin", "Java", "Go"]
Expected Output: false
Q29. Write a Kotlin program to filter out strings longer than 3 characters using a lambda expression.
Input: strings = ["Kotlin", "Go", "Java"]
Expected Output: ["Go"]
Q30. Write a Kotlin program to find the sum of even numbers in a list using a lambda expression.
Input: numbers = [1, 2, 3, 4, 5]
Expected Output: 6
Q31. Write a Kotlin program to find the length of the longest string in a list using a lambda expression.
Input: strings = ["Kotlin", "Java", "Python"]
Expected Output: 6
Q32. Write a Kotlin program to find the number of vowels in a string using a lambda expression.
Input: str = "Kotlin"
Expected Output: 2
Q33. Write a Kotlin program to create a lambda expression that calculates the square root of a number.
Input: num = 16
Expected Output: 4.0
Q34. Write a Kotlin program to create a lambda expression that checks if a number is divisible by 3.
Input: num = 9
Expected Output: true
Q35. Write a Kotlin program to check if a list contains any even number using a lambda expression.
Input: numbers = [1, 3, 5, 6]
Expected Output: true
Q36. Write a Kotlin program to find the number of strings in a list that contain the letter "e" using a lambda expression.
Input: strings = ["Kotlin", "Java", "Python"]
Expected Output: 2
Q37. Write a Kotlin program to sum the elements of a list of doubles using a lambda expression.
Input: numbers = [1.5, 2.5, 3.5]
Expected Output: 7.5
Q38. Write a Kotlin program to check if a list of integers contains all unique elements using a lambda expression.
Input: numbers = [1, 2, 3, 3]
Expected Output: false
Q39. Write a Kotlin program to find the average of the numbers in a list using a lambda expression.
Input: numbers = [2, 4, 6, 8]
Expected Output: 5.0
Q40. Write a Kotlin program to create a lambda expression that subtracts two numbers.
Input: a = 9, b = 5
Expected Output: 4
Q41. Write a Kotlin program to create a lambda expression that checks if a number is positive.
Input: num = 3
Expected Output: true
Q42. Write a Kotlin program to calculate the sum of elements at odd indices in a list using a lambda expression.
Input: numbers = [1, 2, 3, 4, 5]
Expected Output: 6
Q43. Write a Kotlin program to check if a list contains only non-negative integers using a lambda expression.
Input: numbers = [-1, 2, 3]
Expected Output: false
Q44. Write a Kotlin program to find the first negative number in a list using a lambda expression.
Input: numbers = [1, 2, -3, 4]
Expected Output: -3
Q45. Write a Kotlin program to filter out strings that are longer than 4 characters using a lambda expression.
Input: strings = ["Kotlin", "Java", "Go"]
Expected Output: ["Kotlin"]
Q46. Write a Kotlin program to calculate the total length of all strings in a list using a lambda expression.
Input: strings = ["Kotlin", "Java", "Python"]
Expected Output: 17
Q47. Write a Kotlin program to create a lambda expression that calculates the cube of a number.
Input: num = 3
Expected Output: 27
Q48. Write a Kotlin program to convert a list of numbers to their binary form using a lambda expression.
Input: numbers = [1, 2, 3]
Expected Output: ["1", "10", "11"]
Q49. Write a Kotlin program to remove all elements from a list that are less than 10 using a lambda expression.
Input: numbers = [5, 10, 15]
Expected Output: [10, 15]
Q50. Write a Kotlin program to find the number of characters in a list of strings using a lambda expression.
Input: strings = ["Kotlin", "Java", "Python"]
Expected Output: 17