Skip to content

Instantly share code, notes, and snippets.

View imeanup's full-sized avatar

Anupam imeanup

View GitHub Profile
@imeanup
imeanup / homebrew.md
Last active March 23, 2024 12:03
Installing homebrew and setting up the gcc, atcoder library in Mac OS (M2 Silicon)

Install Homebrew

Offical website brew

  1. Open terminal.

  2. Copy past the command and hit return.

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
@imeanup
imeanup / Maximum Toll Revenue Barclays OA.md
Created December 18, 2023 21:07
Maximum Toll Revenue Barclays OA.md

Barclays

In a state, $N$ cities with unique city codes from $1$ to $N$ are connected by $N-1$ roads. The road network is in the form of a tree of which each road connects two cities. A path is a road, or a combination of roads, connecting any two cities. Each road has a toll booth that collects a toll equal to the maximum number of paths of which that particular road is part. The state transportation authority wishes to identify the road on which the maximum toll revenue is collected. Write an algorithm to help the transportation authority identify the pair of cities connected by the road on which the maximum toll revenue is collected. The output should be sorted in increasing order. If more than one road collects the same total revenue, then output the pair of cities that have the smaller city code.

Input

  • The first line of the input consists of an integer - num, representing the number of cities in the state ($N$).
@imeanup
imeanup / Chat Application Flipkart OA.md
Created December 18, 2023 20:06
Chat Application Flipkart OA

For a chat application, a team of developers needs to study the different message writing patterns of the users. Some users write long messages and some users write short messages. As a part of the study the developers have a sequence of lengths of N messages in their system in the order in which these were sent in a chat by the users. The developer must select a homogenous sequence such that the maximum length of a message is less than double the minimum length of a message in the selected sequence. For selection, only the messages from one of the ends of the sequence can be removed. The system must remove the minimum number of messages while fulfilling the developer’s requirement.

Write an algorithm to find the minimum number of messages that must be removed so that the maximum length of a message is less than double the minimum length of a message in the final selected sequence.

InputThe first line of the input consists of an integer – msgList_size, representing the n

@imeanup
imeanup / Company Share Flipkart OA.md
Created December 18, 2023 19:53
Company Share Flipkart OA

Question

A company is assigned a project to develop an online share trading application. In the application, there are two groups of shares i.e. group 1 and group 2. Group 1 has N number of shares identified by codes from 0 to (N-1), and group 2 has M number of shares identified by share codes 0 to (M-1). Both groups consist of share positions in the market. The share positions can be similar between the groups and also within the group. The share application must be designed with an algorithm that provides maximum profit to its users at minimum cost by swapping the shares' position in group 1. In one operation, the application swaps the share positions of any two shares in group 1 so that the share position in group 1 with respect to its code becomes unequal to the share position in group 2. The cost of the operation is calculated as the sum of the share codes. For the next similar operation the new share positions in group 1 will be considered. The whole process continues until each share posi

@imeanup
imeanup / String operation IBM OA.md
Last active December 18, 2023 19:26
String operations IBM OA

Question

On a given string perform following operations. If operation is roll backward(L) then shift all character to one backward over given substring(‘b’ -> ‘a’, ‘a’ -> ‘z’). If operation is roll forward(R) then shift all character to one forward over given substring(‘b’ -> ‘c’, ‘z’ -> ‘a’).

Example

Input:
‘abc’, [‘0 0 L’, ‘2 2 L’, ’0 2 R’]
Output:
‘acc’
@imeanup
imeanup / Paper Cutter Points Turning OA.md
Last active December 16, 2023 17:35
Paper Cutter Points Turning OA

Turning

Paper Cutter Points

Given a paper s written on it with a sequence of x's and o's, your goal is to cut the paper s into two pieces in a way to get the largest number of points, and return that number of points.

Points are calculated after the cut by summing up the number of x's on the left half of the paper and the number of o's on the right half of the paper.

Example:

@imeanup
imeanup / Make Array Equal.md
Created December 16, 2023 14:59
Marke Array Equal Microsoft OA

Question

There is an array $A$ of $N$ integers and two types of operations that can be performed on the elements of the array:

  • increment a single element of $A$, which costs $C_1$;
  • increment two elements of $A$, which costs $C_2$. The chosen elements need to be in different positions.

What is the minimum total cost operations that will make all elements of $A$ equal? As the result may be large, return its last nine digits without leading zeros (in other words, return the result modulo $10^9$).

Write a function:

@imeanup
imeanup / Divisor_Queries.md
Last active December 16, 2023 12:44
Divisor Queries

#include <bits/stdc++.h>
using namespace std;
struct FenwickTree{
    vector<int> bit;
    int n;
@imeanup
imeanup / Arrays_and_Queries.md
Last active December 16, 2023 16:58
Arrays and Queries

#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005

struct SegmentTree{
@imeanup
imeanup / Salary_Day.md
Created December 14, 2023 10:35
Salary Day