How to write code in hiring tests(online)?

I like to write the code in my own way inside [int main()] function in C++.

But hiring tests forced me to write code inside some function and well yeah, I screwed up.

So I have many doubts, please clear it up .

Their compiler show stuff like this:-

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

int solution(vector <int > &v)
{

}

Over.

There is no int main() allowed here.

So what does it mean ? I don’t have to read the input ? I already know the input ?

If I want to write a dfs function, am I allowed to create a function above this function ?

If I want to declare a global array, am I allowed to write it above ?

How does their compiler read the array elements when I did not read it on my own ?

Please clear these doubts… @l_returns @ssrivastava990

I know my doubts are very trivial, don’t judge me as I have started coding recently…

2 Likes

You cannot write like you want in a company.
You need to meet their standards and requirements.
It means they will append int main function in your code and will scan input and print output on your behalf and will pass respective inputs to your function. ( You cannot change input parameters of function but you can rename it)
You can create another function and also declare global variables if required.
You can also try to include libraries which are not included already.

6 Likes