#2667

Create Hello World Function

Easy
ClosureHigher-order functions
LeetCode ↗

Approaches

Brute ForceOptimal
Complexity Comparison
Brute ForceOptimal Solution
Time
O(1)
O(1)
Space
O(1)
O(1)
💡

Intuition

Time O(1)Space O(1)

The optimal solution is essentially the same as the brute force approach since the problem is inherently simple. We just need to ensure that the function we return always gives 'Hello World', regardless of input.

⚙️

Algorithm

3 steps
  1. 1Step 1: Define a function called createHelloWorld.
  2. 2Step 2: Inside createHelloWorld, define a function that ignores its parameters.
  3. 3Step 3: Return the inner function that always returns 'Hello World'.
solution.py4 lines
1def createHelloWorld():
2    def hello(*args):
3        return 'Hello World'
4    return hello

Complexity note: The complexity remains O(1) for both time and space as we are still returning a fixed string without processing any input.

  • 1The function returned by createHelloWorld does not depend on input arguments.
  • 2The problem is fundamentally simple, focusing on function return behavior.

Solutions and explanations are original Tejav content. Problem titles © LeetCode — use the LeetCode button above for the full problem statement.