
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ code to find how long TV are on to watch a match
Suppose we have an array A with n elements. Amal wants to watch a match of 90 minutes and there is no break. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Amal immediately turns off the TV. There will be n interesting minutes represented by the array A. We have to calculate for how many minutes Amal will watch the game.
So, if the input is like A = [7, 20, 88], then the output will be 35, because after 20, he will still watch the game till 35, then turn off it.
Steps
To solve this, we will follow these steps −
Define an array a of size: 100. n := size of A for initialize i := 1, when i <= n, update (increase i by 1), do: a[i] := A[i - 1] if a[i] - a[i - 1] > 15, then: Come out from the loop return minimum of (a[i - 1] + 15) and 90
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; int solve(vector<int> A){ int i, a[100]; int n = A.size(); for (i = 1; i <= n; i++){ a[i] = A[i - 1]; if (a[i] - a[i - 1] > 15) break; } return min(a[i - 1] + 15, 90); } int main(){ vector<int> A = { 7, 20, 88 }; cout << solve(A) << endl; }
Input
{ 7, 20, 88 }
Output
35
- Related Articles
- Why is it bad to watch TV while eating?
- C++ code to find how long person will alive between presses
- How to delete watch history on YouTube app?
- How To Turn Your TV Into Smart TV
- How to delete videos from “Watch later” on YouTube?
- How to manage watch time on YouTube mobile App?
- How to Stop Your Smart TV From Spying on You?
- How to delete videos from Watch later on YouTube Mobile App?
- How to implement a long click listener on a Android listview?
- C++ code to find score of winning square on a square board
- How to connect your YouTube mobile App to TV?
- How to run Python code on Google Colaboratory?
- C++ Program to find which episode we have missed to watch
- C++ code to find different winner and non-winner counts on a contest
- How to run long time process on Udev event

Advertisements