Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
      • Data Structures Solutions
    • Leetcode Solutions
    • HackerEarth 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 *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

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