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.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Artificial Intelligence
  3. Digital Image Analysis
  4. Count the Faces

Count the Faces

Problem
Submissions
Leaderboard
Discussions

You are provided with images of people at meetings, gatherings, group photos etc. Count the number of faces you can spot in each image. There will be no more than faces in each of the images. Assume that half or more of each face will be visible.

Here are the first three images corresponding to the 3 sample test cases which are executed on hitting "run".



Input Format

The first line of input will contain two integers, and , representing the number of rows and columns of image pixels, respectively.

A 2D grid of pixel values will be provided (in regular text format through STDIN) that represent the pixel-wise values from the images. The images were originally in JPG or PNG formats.

Each pixel will be represented by three comma separated values denoting the Blue, Green and Red components, respectively. The pixel values will be in the range to . There will be a space between consecutive pixels in the same row.

No input test case exceeds 15MB in size, most are within 5MB and many are less than 1MB. So you may gradually iterate on your solution to handle larger and more complex cases. Take care to account for very different kinds of faces!

Output Format

Output a single integer, the number of faces spotted in the provided image.

Sample Input

This example is for explanation only. The real inputs will be larger than this and will contain rows and columns.

3 3  
0,0,200 0,0,10 10,0,0
90,90,50 90,90,10 255,255,255
100,100,88 80,80,80 15,75,255

The first line indicates the number of rows and columns x. The above is an image represented by x pixels. For each pixel, the Blue, Green and Red values are provided, separated by commas.

The top left pixel has Blue , Green , Red .
The top right pixel has Blue , Green , Red .
The bottom right pixel has Blue , Green , Red .
The bottom left pixel has Blue , Green , Red .

Sample Output

1

Author

PRASHANTB1984

Difficulty

Hard

Max Score

100

Submitted By

159

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website