I took the online assessment. It had two parts.
- DSA: minimum adjacent swaps for a binary array
Given an array containing only 0s and 1s, rearrange it so that all 0s are at one end and all 1s are at the other. Either ordering was allowed: 000...111 or 111...000. In one move, I could swap two adjacent elements. I had to return the minimum number of moves required.
def minMoves(arr):
pass
For [0, 1, 0, 1], the answer was 1, because one adjacent swap produced [0, 0, 1, 1]. The approximate constraints were 1 <= n <= 100,000 and arr[i] in {0, 1}.
- AI coding round: fix Django post creation
A Django and React blogging platform had a backend bug: users completed every required field but could not create and publish a post. I needed to fix this endpoint:
POST /api/posts/
X-User-Id: <user_id>
The request body was:
{
"title": "string",
"content": "string",
"excerpt": "string",
"category": "string",
"tags": ["string"],
"readTime": 5
}
The required behavior was to read fields from request.data; require title, content, and category; generate defaults for optional fields; associate the post with the user from X-User-Id; save it to the database; and return HTTP 201. The response needed the expected JSON structure, including _id and a nested author, and the post needed to appear under My Posts.
The fix had to pass two predefined tests: test_create_post_with_expected_response_structure_and_values and test_save_created_post_to_database.
Discussion
Loading comments…