Created
December 24, 2024 17:47
-
-
Save MahraibFatima/f7b90cf10ea9b1137434681f6401bed6 to your computer and use it in GitHub Desktop.
Safe examples: "#####", "## ####", "# ##", "### #", " ####" Unsafe examples: "# # ###", " # ##", " ## ## ", "# #### #"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Online C++ compiler to run C++ program online | |
#include <iostream> | |
using namespace std; | |
bool isValidBridge( string s) { | |
char pre = '#'; | |
int gap_cnt= 0, curr_gap= 0; | |
for(int i= 0; i<s.length(); ++i) { | |
if(s[i] == ' ') curr_gap++; | |
if(pre != s[i] && s[i] == ' ') gap_cnt++; | |
pre = s[i]; | |
if(gap_cnt>1 || curr_gap>2) return false; | |
} | |
return (gap_cnt <= 1 && curr_gap <= 2); | |
} | |
int main() { | |
// Write C++ code here | |
string str= "# # "; | |
if(isValidBridge(str)) | |
cout << "True"; | |
else | |
cout << "False"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment