Office Rostering problem solution code (Zone 2) Round 1 TCS CodeVita Season 12
Office Rostering problem solution here
In Python 3 language
Zone 2 (round 1) TCS codevita season 12
def office_rostering(N, M, friendships, K):
# Create adjacency list to represent friendships
friends = {i: [] for i in range(N)}
for a, b in friendships:
friends[a].append(b)
friends[b].append(a)
# Initialize all employees as WFO (1 for WFO, 0 for WFH)
attendance = [1] * N
total_rostering = sum(attendance)
days = 1
while total_rostering < K:
# Calculate attendance for the next day
next_day_attendance = [0] * N
for i in range(N):
friends_wfo = sum(attendance[friend] for friend in friends[i])
if attendance[i] == 1: # WFO today
next_day_attendance[i] = 1 if friends_wfo == 3 else 0
else: # WFH today
next_day_attendance[i] = 1 if friends_wfo < 3 else 0
# Update attendance and calculate rostering
attendance = next_day_attendance
total_rostering += sum(attendance)
days += 1
return days
# Input parsing
def main():
# Read input
N, M = map(int, input().split())
friendships = [tuple(map(int, input().split())) for _ in range(M)]
K = int(input())
# Solve and print result
result = office_rostering(N, M, friendships, K)
print(result)
# Example usage
if __name__ == "__main__":
main()
Comments
Post a Comment