write 10 function example for each of easy , medium and hard , so that I can ask a question in a coding test exam
Assistant
Certainly, crafting a coding test exam requires a good balance of easy, medium, and hard questions to accurately assess the candidates' understanding of programming and problem-solving skills. Below are 10 examples of functions for each difficulty level, primarily designed with a generic approach for clarity and adaptability to different programming languages.
Easy
Calculate Sum: Given two numbers, write a function to calculate and return their sum.
Convert Celsius to Fahrenheit: Write a function that converts Celsius temperatures to Fahrenheit.
Find the Maximum of Two Numbers: Write a function that returns the maximum of two numbers.
Calculate Area of a Circle: Given the radius, write a function to return the area of a circle.
Check Even or Odd: Write a function that checks if a number is even or odd.
String Length: Write a function to return the length of a given string.
Count Vowels: Write a function that counts and returns the number of vowels in a given string.
Factorial: Write a function that calculates the factorial of a given number.
List Sum: Given a list (or array) of numbers, write a function to calculate the sum.
First Character: Write a function that returns the first character of a string.
Medium
Fibonacci Sequence: Write a function that generates and returns the first n numbers of the Fibonacci sequence.
Palindrome Check: Write a function that checks if a given string is a palindrome.
Find Prime Numbers: Write a function to find all prime numbers up to a given number n.
Merge Two Sorted Lists: Given two sorted lists, write a function to merge them into a single sorted list.
Greatest Common Divisor: Write a function to find the greatest common divisor of two numbers.
Convert Roman Numerals to Integer: Write a function that converts a string of Roman numerals to its integer value.
Anagrams Check: Write a function to check if two given strings are anagrams of each other.
Reverse Words in a Sentence: Write a function to reverse the order of words in a given sentence.
Levenshtein Distance: Write a function to calculate the Levenshtein distance between two strings.
Rotate Array: Write a function to rotate an array to the right by n steps.
Hard
Knapsack Problem Solution: Write a function to solve the 0/1 knapsack problem.
Sudoku Solver: Write a function that solves a given Sudoku puzzle.
Longest Substring Without Repeating Characters: Write a function to find the length of the longest substring without repeating characters.
Merge Sort: Implement the merge sort algorithm in a function.
Binary Search Tree Validity: Write a function to check if a binary search tree is valid.
LRU Cache Implementation: Design and implement an LRU (Least Recently Used) cache.
Graph Cycle Detection: Write a function to detect a cycle in a graph.
Serialize and Deserialize Binary Tree: Write functions to serialize a binary tree to a string and deserialize a string back to a binary tree.
Minimum Window Substring: Write a function to find the minimum window in a string which will contain all the characters of another string.
Dynamic Programming: Coin Change: Write a function to compute the fewest number of coins that you need to make up a given amount of money.
These examples should provide a solid framework for a coding test, covering a range of concepts from basic programming and data structures to advanced algorithms and problem-solving strategies.