Ball coloring
Easy Accuracy: 67.32% Submissions: 98 Points: 2

Given n balls . All of them are initially  uncolored . You have to color the balls with two colors RED and BLUE such that there can be atmost 2 positions where a RED ball is touching BLUE ball or vice versa. You have to color all the balls.Find the number of ways in which balls can be colored.

Example 1:

Input: n = 1
Output: 2
Explanation: Possible ways to color are {{R},{B}}. 
So the answer is 2 .


Example 2:

Input: n = 2
Output: 4
Explanation: Possible ways to color are 
{{RB},{BR},{RR},{BB}}.So the answer is 4.


Your Task:  
You dont need to read input or print anything. Complete the function noOfWays() which takes n as input parameter and returns
 the number of ways in which balls can be colored.

Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Constraints:
1<= n <=105

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Ball coloring

Output Window