[Solved] What would be the most efficient way to find if a number n contains a specific number k?

If finding a count of how many times a specific digit appears in a number is what you mean, than the complexity will be O(n) where n is the length of the string (number): char x = ‘7’; std::string number(“9876541231654810654984431”); int count = 0; for (size_t i = 0; i < number.size(); ++i) if (number[i] … Read more

[Solved] What is the Big O complexity of this program…I got O(2^n) but i am not able to find correct answer [closed]

A different argument: Your algorithm recurses until it “bottoms out” at fib(1) which returns 1. So you are getting the fibonacci number by doing (fibonacci number) calls and adding the 1s. So fib(n) is O(fib(n)). Binet’s Fibonacci formula can be written as fib(n) == int(0.5 + (phi ** n) / (5 ** 0.5)) where phi … Read more