




Sponsored
Sponsored
This approach uses the concept of closures to return a function that ignores its arguments and always returns the string 'Hello World'. In this method, createHelloWorld returns a new function that consistently returns the string when invoked.
Time Complexity: O(1) as the function performs a constant-time operation.
Space Complexity: O(1) since it doesn't use any extra space dependent on input size.
1In Python, we define a function create_hello_world that returns a lambda function. This lambda function does not take any parameters and always returns "Hello World".
This approach directly returns a function without using intermediate variables like closures. The returned function will always output 'Hello World', ignoring any provided arguments.
Time Complexity: O(1). The function executes a single return instruction.
Space Complexity: O(1) as there are no dynamic allocations.
1using System;
2
3public class HelloWorld {
4    public static string HelloWorldFunction() {
5        return "Hello World";
6    }
7
8    public static Func<string> CreateHelloWorld() {
9        return HelloWorldFunction;
10    }
11}In C#, we define a separate method HelloWorldFunction which returns "Hello World". The CreateHelloWorld method returns a delegate pointing to HelloWorldFunction.