Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Diamonds problem solution

YASH PAL, 31 July 202413 February 2026
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 solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes