Header Ads Widget

Employee rating | hackerearth solution

 Problem

You are an IT company's manager. Based on their performance over the last N working days, you must rate your employee. You are given an array of N integers called workload, where workload[i] represents the number of hours an employee worked on an ith day. The employee must be evaluated using the following criteria:

  • Rating = the maximum number of consecutive working days when the employee has worked more than 6 hours.

You are given an integer where N represents the number of working days. You are given an integer array workload where workload[i] represents the number of hours an employee worked on an ith day.

Task

Determine the employee rating.

Example

Assumptions

  • N = 12
  • workload = [2, 3, 7, 8, 7, 6, 3, 8, 12, 11, 12, 10]

Approach

Workload with consecutive hours > 6 = [2, 3, 7, 8, 7, 6, 3, 8, 12, 11, 12, 10] =>  Longest Interval =  [8,12,11,12,10]

Therefore return 5.

Function description

Complete the Solve() function provided in the editor below that takes the following arguments and returns the employee rating:

  • N: Represents the number of working days
  • workload: where workload[i] represents the number of hours an employee worked on an ith day

Input format

  • The first line contains an integer N denoting the number of working days.
  • The second line contains a space-separated integer array workload where workload[i] represents the number of hours an employee worked on an ith day.

Output format

Print the employee rating.

Constraints

1105

1[]12

Sample Input
7
3 7 8 12 4 9 8
Sample Output
3
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Workload with consecutive hours > 6 = [7 8 12 4 9 8] =>  Longest Interval = [7 8 12]

Therefore, return 3.

Code(C++):-

#include<bits/stdc++.h>
using namespace std;
int solve (int N, vector<int> workload) {
int count=0;
int temp=0;
for(int i=0;i<N;i++){
if(workload[i]>6){
count++;
}
else{
temp=max(temp,count);
count=0;
}
}
return temp;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<int> workload(N);
for(int i_workload = 0; i_workload < N; i_workload++)
{
  cin >> workload[i_workload];
}
int out_;
out_ = solve(N, workload);
cout << out_;
}

Code(JAVA):-

import java.io.*;
import java.util.*;
public class TestClass {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter wr = new PrintWriter(System.out);
int N = Integer.parseInt(br.readLine().trim());
String[] arr_workload = br.readLine().split(" ");
int[] workload = new int[N];
for(int i_workload = 0; i_workload < arr_workload.length; i_workload++)
{
   workload[i_workload] = Integer.parseInt(arr_workload[i_workload]);
}
int out_ = solve(N, workload);
System.out.println(out_);
wr.close();
br.close();
}
static int solve(int N, int[] workload){
// Write your code here
int result = 0;
int temp = 0;
for(int i = 0; i < N; i++){
if(workload[i] > 6){
temp++;
}else{
if(temp > result){
result = temp;
}
temp = 0;
}
}
return result;
}
}



Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-


Post a Comment

0 Comments