- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find value of find(x, y) is even or odd in Python

Suppose we have an array nums. We also have another pair (x, y), we need to find whether the value find(x,y) is Odd or Even. The find() is as follows

- find(x, y) = 1 if x > y
- find(x, y) = nums[x]^find(x+1, y) otherwise

So, if the input is like nums = [3,2,7] (x, y) = 1, 2, then the output will be even, because −

- find(1, 2) = nums[1]^find(2,3)
- find(2, 2) = nums[2]^find(3,2)
- find(3, 2) = 1,
- so find(2, 2) = 7, and find(1, 2) = 2^7 = 128, this is even

To solve this, we will follow these steps −

- even := True
- if x > y or nums[x] is odd , then
- even := False

- if x < size of nums - 1 and x < y and nums[x+1] is same as 0, then
- even := False

- if even True, then
- return 'Even'

- otherwise,
- return 'Odd'

## Example

Let us see the following implementation to get better understanding −

def solve(nums, x, y): even = True if x > y or (nums[x] % 2 == 1): even = False if x < len(nums) - 1 and x < y and nums[x+1] == 0: even = False if even: return 'Even' else: return 'Odd' nums = [3,2,7] (x, y) = 1,2 print(solve(nums, x, y))

## Input

[3,2,7], 1, 2

## Output

Even

- Related Questions & Answers
- Java program to find whether given number is even or odd
- Find larger of x^y and y^x in C++
- Find maximum among x^(y^2) or y^(x^2) where x and y are given in C++
- How to find edit text values start from Number is Even or Odd?
- Program to find nearest point that has the same x or y coordinate using Python
- Find value of y mod (2 raised to power x) in C++
- C++ Program to Check Whether Number is Even or Odd
- Python Program for Check if the count of divisors is even or odd
- Check if count of divisors is even or odd in Python
- C Program to Check if count of divisors is even or odd?
- Java Program to check if count of divisors is even or odd
- Find number of pairs (x, y) in an array such that x^y > y^x in C++
- Python Program to Determine Whether a Given Number is Even or Odd Recursively
- Find the value of the function Y = (X^6 + X^2 + 9894845) % 981 in C++
- Java Program to Check Whether a Number is Even or Odd

Advertisements