`{"id":"94478052-517b-40d4-bfce-ee138ef74d27","name":"Push Dominoes","description":"1. There are n dominoes in a line, and we place each domino vertically upright.\r\n2. In the beginning, we simultaneously push some of the dominoes either to the left or to the right.\r\n3. After each second, each domino that is falling to the left pushes the adjacent domino on the left. \r\n4. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right.\r\n5. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces.\r\n6. For the purposes of this question, we will consider that a falling domino expends no additional force to a falling or already fallen domino.\r\n7. You are given a string dominoes representing the initial state where:\r\n a). dominoes[i] = 'L', if the ith domino has been pushed to the left,\r\n b). dominoes[i] = 'R', if the ith domino has been pushed to the right, and\r\n c). dominoes[i] = '.', if the ith domino has not been pushed.\r\n8. Return a string representing the final state.\r\n","inputFormat":"1. dominoes = \"RR.L\"\r\n2. dominoes = \".L.R...LR..L..\"\r\n","outputFormat":"1. \"RR.L\"\r\nExplanation: The first domino expends no additional force on the second domino.\r\n\r\n2. \"LL.RR.LLRRLL..\" ","constraints":"1. n == dominoes.length\r\n2. 1 &lt;= n &lt;= 10^5\r\n3. dominoes[i] is either 'L', 'R', or '.'\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nstring pushDominoes(string str) {\n //write your code here\n}\n\nint main(){\n string str;\n cin>>str;\n string res=pushDominoes(str);\n cout<<res;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n // ~~~~~~~~~~~~~User''s Section~~~~~~~~~~~~~~\r\n public static String pushDominoes(String str) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~~Input Management~~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n String str = scn.nextLine();\r\n String res = pushDominoes(str);\r\n System.out.println(res);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"RR.L","sampleOutput":"RR.L","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"30e6b217-04fc-4ff7-b437-ba508210de9c","name":"Push Dominoes","slug":"push-dominoes","type":1}],"next":{"id":"6cda1954-5529-4f3a-9037-65bee41b8417","name":"Push Dominoes","type":3,"slug":"push-dominoes"},"prev":{"id":"00860204-2852-40f0-a9fc-96c4cc00be84","name":"Furthest Building You Can Reach MCQ","type":0,"slug":"furthest-building-you-can-reach-mcq"}}}`

# Push Dominoes

1. There are n dominoes in a line, and we place each domino vertically upright. 2. In the beginning, we simultaneously push some of the dominoes either to the left or to the right. 3. After each second, each domino that is falling to the left pushes the adjacent domino on the left. 4. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. 5. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. 6. For the purposes of this question, we will consider that a falling domino expends no additional force to a falling or already fallen domino. 7. You are given a string dominoes representing the initial state where: a). dominoes[i] = 'L', if the ith domino has been pushed to the left, b). dominoes[i] = 'R', if the ith domino has been pushed to the right, and c). dominoes[i] = '.', if the ith domino has not been pushed. 8. Return a string representing the final state.

`{"id":"94478052-517b-40d4-bfce-ee138ef74d27","name":"Push Dominoes","description":"1. There are n dominoes in a line, and we place each domino vertically upright.\r\n2. In the beginning, we simultaneously push some of the dominoes either to the left or to the right.\r\n3. After each second, each domino that is falling to the left pushes the adjacent domino on the left. \r\n4. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right.\r\n5. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces.\r\n6. For the purposes of this question, we will consider that a falling domino expends no additional force to a falling or already fallen domino.\r\n7. You are given a string dominoes representing the initial state where:\r\n a). dominoes[i] = 'L', if the ith domino has been pushed to the left,\r\n b). dominoes[i] = 'R', if the ith domino has been pushed to the right, and\r\n c). dominoes[i] = '.', if the ith domino has not been pushed.\r\n8. Return a string representing the final state.\r\n","inputFormat":"1. dominoes = \"RR.L\"\r\n2. dominoes = \".L.R...LR..L..\"\r\n","outputFormat":"1. \"RR.L\"\r\nExplanation: The first domino expends no additional force on the second domino.\r\n\r\n2. \"LL.RR.LLRRLL..\" ","constraints":"1. n == dominoes.length\r\n2. 1 &lt;= n &lt;= 10^5\r\n3. dominoes[i] is either 'L', 'R', or '.'\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nstring pushDominoes(string str) {\n //write your code here\n}\n\nint main(){\n string str;\n cin>>str;\n string res=pushDominoes(str);\n cout<<res;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n // ~~~~~~~~~~~~~User''s Section~~~~~~~~~~~~~~\r\n public static String pushDominoes(String str) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~~Input Management~~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n String str = scn.nextLine();\r\n String res = pushDominoes(str);\r\n System.out.println(res);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"RR.L","sampleOutput":"RR.L","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"30e6b217-04fc-4ff7-b437-ba508210de9c","name":"Push Dominoes","slug":"push-dominoes","type":1}],"next":{"id":"6cda1954-5529-4f3a-9037-65bee41b8417","name":"Push Dominoes","type":3,"slug":"push-dominoes"},"prev":{"id":"00860204-2852-40f0-a9fc-96c4cc00be84","name":"Furthest Building You Can Reach MCQ","type":0,"slug":"furthest-building-you-can-reach-mcq"}}}` Editor

# Push Dominoes

medium

1. There are n dominoes in a line, and we place each domino vertically upright. 2. In the beginning, we simultaneously push some of the dominoes either to the left or to the right. 3. After each second, each domino that is falling to the left pushes the adjacent domino on the left. 4. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. 5. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. 6. For the purposes of this question, we will consider that a falling domino expends no additional force to a falling or already fallen domino. 7. You are given a string dominoes representing the initial state where: a). dominoes[i] = 'L', if the ith domino has been pushed to the left, b). dominoes[i] = 'R', if the ith domino has been pushed to the right, and c). dominoes[i] = '.', if the ith domino has not been pushed. 8. Return a string representing the final state.

## Constraints

1. n == dominoes.length 2. 1 <= n <= 10^5 3. dominoes[i] is either 'L', 'R', or '.'

## Format

### Input

1. dominoes = "RR.L" 2. dominoes = ".L.R...LR..L.."

### Output

1. "RR.L" Explanation: The first domino expends no additional force on the second domino. 2. "LL.RR.LLRRLL.."

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}RR.L`

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}RR.L`

Discussions

Show Discussion

Related Resources 