We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Beautiful Strings
Beautiful Strings
+ 0 comments Here is my solution in java, javascript, python, C, C++, Csharp HackerRank Beautiful Strings Problem Solution
+ 0 comments Here is Beautiful Strings problem solution - https://programs.programmingoneonone.com/2021/07/hackerrank-beautiful-strings-problem-solution.html
+ 0 comments // this solution without any type of container #include<iostream> typedef int usg_t; int main() { char x, y, z; usg_t dup{ 0 }, dupc{ 0 }, tria{ 0 }, dis{ 0 }; // dup count for X...XX // tria count for XOX // dis count for XO . x = getchar(); y = getchar(); z = getchar(); if ((x < 'a' || x > 'z') || (y < 'a' || y > 'z')) std::cout << 0, exit(0); else if (z < 'a' || z > 'z') std::cout << 1, exit(0); if (x == y) { if (x == z) dis ++, dup++, ++dupc; else dup++, dis += 2; } else { if (x == z) dis += 3, tria++; else if (y == z) dis += 2, dup++, dupc++; else dis += 3; } while (true) { x = y, y = z; z = getchar(); if (z < 'a' || z > 'z') break; if (x == y) { if (x != z) ++dis; } else { if (x != z) { if (y == z) ++dup; else ++dis; } else dis++, tria++; } } std::cout << ((dis * (dis - 1) / 2) + dup - tria) << std::endl; system("pause"); }
+ 0 comments def beautifulStrings(s): perms=permutations(s,2) return len(set(perms))
How Can I pass all the cases ? its just passing single test case... can Anyone give the idea or hints please??
+ 3 comments my python 3 approach some test cases are passed but some are terminated due to timeout error can anyone help:
from itertools import combinations a=input() p=combinations(a,len(a)-2) p=set(p) print(len(p))
Load more conversations
Sort 16 Discussions, By:
Please Login in order to post a comment