Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • 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
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerRank Boxes through a Tunnel solution in c

YASH PAL, 29 July 202414 June 2025

In this HackerRank Boxes through a Tunnel c programming problem solution You are transporting some boxes through a tunnel, where each box is a parallelepiped, and is characterized by its length, width and height.

The height of the tunnel 41 feet and the width can be assumed to be infinite. A box can be carried through the tunnel only if its height is strictly less than the tunnel’s height. Find the volume of each box that can be successfully transported to the other end of the tunnel. Note: Boxes cannot be rotated.

HackerRank Boxes through a Tunnel solution in c programming

HackerRank Boxes through a tunnel problem solution in c programming.

#include <stdio.h>
struct Box
{
    int length, width, height;
};

int volume(struct Box box)
{
    return box.length*box.width*box.height;
}

int lower(struct Box box, int maxHeight)
{
    return box.height < maxHeight;
}

int main()
{
   int n;
   scanf("%d", &n);
   struct Box boxes[100];
   for (int i = 0; i < n; i++)
      scanf("%d%d%d", &boxes[i].length, &boxes[i].width, &boxes[i].height);
   for (int i = 0; i < n; i++)
      if (lower(boxes[i], 41))
         printf("%d\n", volume(boxes[i]));
   return 0;
}

Second solution

#include <stdio.h>
#include <stdlib.h>
#define MAX_HEIGHT 41

typedef struct {
    int height;
    int length;
    int width;
}box;

int get_volume(box b) {
    return b.length * b.height * b.width;
}

int is_lower_than_max_height(box b) {
    return b.height < 41 ? 1 : 0;
}

int main()
{
  int n;
  scanf("%d", &n);
  box *boxes = malloc(n * sizeof(box));
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &boxes[i].length, &boxes[i].width, &boxes[i].height);
  }
  for (int i = 0; i < n; i++) {
    if (is_lower_than_max_height(boxes[i])) {
      printf("%d\n", get_volume(boxes[i]));
    }
  }
  return 0;
}
coding problems solutions HackerRank C Solutions Hackerrank Problems Solutions cHackerRank

Post navigation

Previous post
Next post

Leave a Reply

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

HackerRank C Solutions
Hello world in c solution
Playing with characters solution
sum and difference of two numbers solution
functions in c solution
pointers in c solution
Conditional statements in c solution
For loop in c solution
Sum of Digits of a five-digit number solution
Bitwise operators solution in c
Printing pattern using loops solution in c
1D Arrays in c solution
Array Reversal solution in c
Printing Tokens solution in c
Digit Frequency solution in c
Dynamic Array in c solution
Calculate the Nth term solution in c
Students Marks sum solution in c
Sorting Array of strings solution in c
Permutations of strings solution in c
Variadic functions in c solution
Querying the documents solution in c
Boxes through a tunnel solution in c
Small Triangles, Large Triangles solution in c
post-transition solution in c
Structuring the document solution in c

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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