Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Check for equality of two arrays #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
anantkaushik merged 4 commits into master from problem
Jan 28, 2020
Merged

Check for equality of two arrays #3

anantkaushik merged 4 commits into master from problem
Jan 28, 2020

Conversation

Copy link
Owner

@nirmalnishant645 nirmalnishant645 commented Jan 26, 2020

Check for most optimal solution

Comment on lines 39 to 52
def equal(arr1, arr2):
res = 0
for i in range(len(arr1)):
res ^= arr1[i]
res ^= arr2[i]
return 0 if res else 1

t = int(input())
while t > 0:
n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
print(equal(arr1, arr2))
t -= 1
Copy link
Collaborator

@anantkaushik anantkaushik Jan 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if a is [1,2,1] and b is [3,2,3]

nirmalnishant645 reacted with thumbs up emoji
Comment on lines 39 to 44
def equal(arr1, arr2):
res1 = res2 = 0
for i in range(len(arr1)):
res1 ^= arr1[i]
res2 ^= arr2[i]
return 1 if res1 == res2 else 0
Copy link
Collaborator

@anantkaushik anantkaushik Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if a = [1,2,2,1] and b = [3,3,4,4]

Comment on lines 42 to 43
res1 ^= arr1[i]
res2 ^= arr2[i]
Copy link
Collaborator

@anantkaushik anantkaushik Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need two variables for this?

@anantkaushik anantkaushik merged commit 3a15e08 into master Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@anantkaushik anantkaushik anantkaushik approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /