Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerEarth Diamonds problem solution

YASH PAL, 31 July 2024
In this HackerEarth Diamonds problem solution, Roman loved diamonds. Monica decided to give him a beautiful gift on Valentine’s Day. Her idea of diamonds was different though. She lit up all the windows of her rectangular building with N floors and M windows on each floor, with 2 shapes – / or . According to her, a diamond was made when such a shape was created:
/
/
we have Given the shape of lights in all the windows, help Roman count the number of diamonds formed.
Note: The components of the diamond should be adjacent to each other.
HackerEarth Diamonds problem solution

HackerEarth Diamonds problem solution.

#include <bits/stdc++.h>
using namespace std;

char a[1024][1024];

int main() {
int t;cin>>t;
while(t--) {
int n,m;
cin>>n>>m;
assert(n>=2 && n<=1000);
assert(m>=2 && m<=1000);
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
cin>>a[i][j];
}
}
int cnt=0;
for(int i=0;i<n-1;i++) {
for(int j=0;j<m-1;j++) {
if(a[i][j]=='/' && a[i][j+1]=='\' && a[i+1][j]=='\' && a[i+1][j+1]=='/') {
cnt++;
}
}
}
cout<<cnt<<"n";
}
}
coding problems

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes