You are on page 1of 1

Practice Guided Paths Interview Prep Challenges Knowledge Centre

Problem Submissions Solution Python (3.5)

Contribute a new Your Code Solution Report


Approach 1
approach
Approach 2 1 '''
2   Time complexity: O(1)
Contributed By 3   Space complexity: O(1).
Shrey Pansuria | Level 1
4 '''
5 ​
Swapping using a temporary 6 def swap(a, b):
variable 7    temp = 0
Take input in two integer datatype variables, a and 8    # Store the value of a in temp.
b. Create a temporary variable temp and initialize it 9    temp = a
equal to a. Now make a equal to b, and finally 10    # Make a equal to b.
make b equal to temp. Print a and b.
11    a = b
12    # Make b equal to temp.
Time Complexity 13    b = temp
O(1),  14    
15    return a, b
The Time Complexity is O(1).

Space Complexity
O(1), 

The Space Complexity is O(1).

Suggest Edit

Console

Rate this Show Saving


problem Previous Next Hint Code... Run Code S

You might also like