Function Coding Questions are similar to normal coding questions apart from the fact that one does not need to read input and print output from standard I/O while writing solutions.
In function coding question, one just needs to complete a function already written in the code editor. You need to work on inputs provided as a parameter to this function and instead of printing the result you will have to return it from the function.
Let’s take the example of a sample function problem: Equilibrium Index of an Array. The pattern of question is almost the same as that of normal programming questions. In function problems, you can notice an additional information provided as “Task” after the output format which clearly explains that the user only needs to complete a function and return the result from it.
You can also see that in the code editor for this question there is already a function written with name findEquilibrium().
This function accepts an array A and an integer n which denotes the size of the array A. You can see in the above image that the body of this function is empty. You need to write your complete code inside the body of this function and return the result from it without writing a separate main() function. You must assume that there is already a main() function written which is invoking this function and write your program accordingly.
Below is the complete working solution for the above question:
Important things to remember
- One should assume that a main() function is already present which is invoking the current function and should not write a separate main() function.
- Use inputs as provided in the function parameters.
- Return result from the function instead of printing it.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, ...
- Must Do Coding Questions Company-wise
- How to answer a coding question in an Interview?
- Practice for cracking any coding interview
- TCS Coding Practice Question | Reverse a String
- TCS Coding Practice Question | Palindrome String
- TCS Coding Practice Question | Check Palindrome Number
- TCS Coding Practice Question | Reverse a Number
- TCS Coding Practice Question | Sum of Digits of a number
- TCS Coding Practice Question | Checking Leap Year
- TCS Coding Practice Question | Checking Prime Number
- TCS Coding Practice Question | Prime Numbers upto N
- TCS Coding Practice Question | Greatest of 3 Numbers
- TCS Coding Practice Question | Concatenate 2 Strings
- TCS Coding Practice Question | Swap two Numbers
- TCS Coding Practice Question | LCM of 2 Numbers
- TCS Coding Practice Question | HCF or GCD of 2 Numbers
- TCS Coding Practice Question | Average of 2 Numbers
- TCS Coding Practice Question | Factorial of a Number
- TCS Coding Practice Question | Fibonacci Series
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.