Join Regular Classroom : Visit ClassroomTech

Nagarro Question Solved | Planning the street | Codewindow.in

Hot Topics

Company Based – Codewindow

Interview Questions
1. TCS Technical Questions
2. CTS Technical Questions
3. Infosys Technical Questions
4. Capgemini Technical Questions
5. IBM Technical Questions
6. Wipro Technical Questions
7. Accenture Technical Questions
8. Deloitte Technical Questions
9. MindTree Technical Questions
10. NTT Data Technical Questions
11. Persistent Technical Questions
12. Hexaware Technical Questions
13. ZOHO Technical Questions
14. HCL Technical Questions
15. Genpact Technical Questions
16. udostres Technical Questions
17. samsung research Technical Questions
18. Media.net Technical Questions
19. Tejas Network Technical Questions
20. Kantar Technical Questions
21. Itron Technical Questions
22. Fractal Analyst Technical Questions
23. Lexmark International Technical Questions
24. Infeneon Technologies Technical Questions
25. Razorpay Technical Questions
26. payu Technical Questions
27. Navi Technical Questions
28. Tata Cliq Technical Questions
29. Grab Technical Questions
30. Schlumberger Technical Questions
31. Latenview Analytics Technical Questions
32. GreayB Technical Questions
33. Tally solution Technical Questions
34. Amagi Technical Questions
35. HFCL Technical Questions
36. Slice Technical Questions
37. Larsen & Turbo Technical Questions
38. Zenser Technical Questions
39. Siemens Technical Questions
40. Exon Movie Technical Questions
41. Gupshup Technical Questions
42. Smart cube Technical Questions
43. Celebal Tech Technical Questions
44. Teg Analytics Technical Questions
45. Commvault Systems Technical Questions
46. Incuture Technical Questions
47. Tiger Technical Questions
48. Bridgei2i Technical Questions
49. code nation Technical Questions
50. DE Show Technical Questions
51. Amazon Technical Questions
52. Flipkart Technical Questions
53. Morgan Stanly Technical Questions
54. duutsche bank Technical Questions
55. textas Technical Questions
56. pwc Technical Questions
57. salesforce Technical Questions
58. optum Technical Questions
59. Nvidia Technical Questions
60. Itc Infotech Technical Questions
61. linkedin Technical Questions
62. Adobe Technical Questions

Nagarro Question Solved | Planning the street | Codewindow.in

King George has built an exclusive street for his executives-class employees to build their

houses.The street is divided into M sections. Each section corresponds to two plots.one on each side of the street.

He has assigned you to plan the street.You have to decide on which plots along the street 

can the new building be built in order to do this.you first need to calculate the number of possible

ways in which free plots can be assigned to buildings,keeping in mind the restriction mentioned below-

No two consecutive plots can have building on them.This is done to ensure a sense of free space in the area.

Your task it to find and return the number of possible assignments.

 

Input Specification:

Input1: An integer M depending the number of sections(Ms 1000)

Output Specifications:

Return the number of possible assignments.

 

Example 1:

Input1: 3

Output: 25

Explanation:

If we look at one of the street and mark X as a plot where building is allowed and

Y as a free plot,we have XYX,YXY,YYX,XYY,YYY Because the same

number exists on the other side,we have 5*5=25 combinations.

Therefore 25 is returned as the output.

 

There are 6 different ways to paint 4 houses such that exactly 1 pair of adjacent houses has different colours. Hence output is 6.

Example 2:

Input: 2

Output: 9

Explanation:

If we look at one side of the street and mark X as a plot where

building is allowed and Y as a free plot,we have XY,YX,YY Because

the same number exists on the other side.we have 3*3=9 combinations.

Therefore 9 is returned as the output.

Input:

2

Output:

9

Python

#https://codewindow.in
#join our telegram channel @codewindow

def king_george(number: int) -> int:
    x = [0, 1, 1]
    y = [0, 1, 2]
    for i in range(3, number + 1):
        x += [y[i - 1]]
        y += [x[i - 1] + y[i - 1]]
    result = x[number] + y[number]
    return result * result

n = king_george(int(input()))
print(n)

C++

// https://codewindow.in
// join our telegram channel @codewindow

#include 
#include 
using namespace std;

void king_george(int number)
{
    int x[100] = {0, 1, 1};
    int y[100] = {0, 1, 2};
    for (int i = 3; i <= number; i++)
    {
        x[i] += y[i - 1];
        y[i] += x[i - 1] + y[i - 1];
    }
    int result = x[number] + y[number];
    cout <> n;
    king_george(n);
}

JAVA

//https://codewindow.in
//join our telegram channel @codewindow

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class CodeWindow {
    static void king_george(int number) {
        int x[] = new int[100];
        x[0] = 0;
        x[1] = 1;
        x[2] = 1;
        int y[] = new int[100];
        y[0] = 0;
        y[1] = 1;
        y[2] = 2;
        for (int i = 3; i <= number; i++) {
            x[i] += y[i - 1];
            y[i] += x[i - 1] + y[i - 1];
        }
        int result = x[number] + y[number];
        System.out.println(result * result);
    }

    public static void main(String[] args) throws Exception {
        // your code goes here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        king_george(n);
    }
}

Nagarro Solved

Automata Fixing

      

Popular Category

Hot Topics

Company Based – Codewindow

Interview Questions
1. TCS Technical Questions
2. CTS Technical Questions
3. Infosys Technical Questions
4. Capgemini Technical Questions
5. IBM Technical Questions
6. Wipro Technical Questions
7. Accenture Technical Questions
8. Deloitte Technical Questions
9. MindTree Technical Questions
10. NTT Data Technical Questions
11. Persistent Technical Questions
12. Hexaware Technical Questions
13. ZOHO Technical Questions
14. HCL Technical Questions
15. Genpact Technical Questions
16. udostres Technical Questions
17. samsung research Technical Questions
18. Media.net Technical Questions
19. Tejas Network Technical Questions
20. Kantar Technical Questions
21. Itron Technical Questions
22. Fractal Analyst Technical Questions
23. Lexmark International Technical Questions
24. Infeneon Technologies Technical Questions
25. Razorpay Technical Questions
26. payu Technical Questions
27. Navi Technical Questions
28. Tata Cliq Technical Questions
29. Grab Technical Questions
30. Schlumberger Technical Questions
31. Latenview Analytics Technical Questions
32. GreayB Technical Questions
33. Tally solution Technical Questions
34. Amagi Technical Questions
35. HFCL Technical Questions
36. Slice Technical Questions
37. Larsen & Turbo Technical Questions
38. Zenser Technical Questions
39. Siemens Technical Questions
40. Exon Movie Technical Questions
41. Gupshup Technical Questions
42. Smart cube Technical Questions
43. Celebal Tech Technical Questions
44. Teg Analytics Technical Questions
45. Commvault Systems Technical Questions
46. Incuture Technical Questions
47. Tiger Technical Questions
48. Bridgei2i Technical Questions
49. code nation Technical Questions
50. DE Show Technical Questions
51. Amazon Technical Questions
52. Flipkart Technical Questions
53. Morgan Stanly Technical Questions
54. duutsche bank Technical Questions
55. textas Technical Questions
56. pwc Technical Questions
57. salesforce Technical Questions
58. optum Technical Questions
59. Nvidia Technical Questions
60. Itc Infotech Technical Questions
61. linkedin Technical Questions
62. Adobe Technical Questions

We Love to Support you

Go through our study material. Your Job is awaiting.

Recent Posts
Categories