ConsultAdd Inc interview experience Real time questions & tips from candidates to crack your interview

Software Engineer

ConsultAdd Inc
upvote
share-icon
1 rounds | 2 Coding problems

Interview preparation journey

expand-icon
Journey
I prepared through the Coding Ninjas Java + Data Structures course, where I built my foundation in Java and practiced DSA concepts regularly. Alongside the course, I referred to JavaTpoint and GeeksforGeeks for additional notes, quick revisions, and deeper clarity on specific topics. This combination helped me strengthen both my coding practice and theoretical understanding.
Preparation
Topics: Java, Javascript, DSA, Basics of Arrays, Strings
Application process
Where: Coding Ninjas Placement Cell
Eligibility: B.Tech CS/IT (Grad Year-2025 & 2024)

Interview rounds

01
Round
Hard
Online Coding Interview
Duration
Interview date7 Mar 2025
Coding problem2

1. Count Collisions on the Road

You are given n cars on an infinitely long road, numbered from 0 to n-1 from left to right, each at a unique position. You are also given a string directions of length n where each character represents the state of the car at that index:

  • 'L' → car is moving left
  • 'R' → car is moving right
  • 'S' → car is stationary

All moving cars travel at the same speed. The total number of collisions can be calculated as follows:

  • When two cars moving in opposite directions collide, the collision count increases by 2.
  • When a moving car collides with a stationary car, the collision count increases by 1.

After a collision, the cars involved become stationary at the collision point. Cars cannot change direction or state otherwise.

Return the total number of collisions that will happen on the road.

Problem approach

Step 1: Identify Collision Scenarios There are three cases where collisions can happen: Opposite direction collision: A car moving right ('R') collides with a car moving left ('L'), contributing 2 to the collision count. Right-moving car hitting a stationary car ('S'): A moving car 'R' collides with 'S', contributing 1. Left-moving car hitting a stationary car ('S'): A moving car 'L' collides with 'S', contributing 1. After a collision, the cars involved stop moving. 

Step 2: Ignore Non-Colliding Cars at Extremes Any cars moving left ('L') at the start will never collide. Any cars moving right ('R') at the end will never collide. Trim these non-colliding cars from consideration. 

Step 3: Iterate Through the String and Count Collisions Traverse through the filtered string and check where 'R' and 'L' meet. Track stationary cars ('S') that get hit. Keep a counter to track total collisions. 

Step 4: Use a Single Pass and Stack Approach (Optimized) Use a stack or variables to track right-moving cars ('R'). When an 'L' car is encountered, pop from the stack and count collisions. 

Step 5: Implement the Function Efficiently Use a loop to process the collisions in a single pass (O(n) time complexity). Return the total number of collisions.

2. Longest Wiggle Subsequence

A wiggle sequence is defined as a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if it exists) may be either positive or negative.

  • A sequence with one element, or two non-equal elements, is trivially a wiggle sequence.
  • For example:
    • [1, 7, 4, 9, 2, 5] is a wiggle sequence because the differences (6, -3, 5, -7, 3) alternate between positive and negative.
    • [1, 4, 7, 2, 5] is not a wiggle sequence because the first two differences are both positive.
    • [1, 7, 4, 5, 5] is also not a wiggle sequence because its last difference is zero.

A subsequence of a sequence is obtained by deleting some (possibly zero) elements while keeping the remaining elements in their original order.

Given an integer array nums, return the length of the longest wiggle subsequence of nums.

 

Problem approach

Step 1: Understand the Wiggle Property A wiggle sequence requires the differences between consecutive elements to strictly alternate between positive and negative. For each pair of adjacent elements nums[i] and nums[i+1], we calculate: Positive difference: nums[i+1] - nums[i] > 0 Negative difference: nums[i+1] - nums[i] < 0 Zero difference: Does not contribute to a wiggle sequence 

Step 2: Identify the Core Concept (Greedy Approach) Instead of checking all subsequences (O(2^n) time complexity), we use a greedy approach. We count "peaks" and "valleys" because each peak and valley contributes to the wiggle length. 

Step 3: Initialize Variables for Tracking Peaks and Valleys Use prevDiff = 0 to track the previous difference. Use count = 1 because a single element is always a valid subsequence. Iterate through the array while checking for changes in sign. 

Step 4: Traverse the Array and Count Wiggle Points Calculate diff = nums[i] - nums[i-1]. If diff > 0 and prevDiff <= 0, increase count. If diff < 0 and prevDiff >= 0, increase count. Update prevDiff = diff. After iterating through the array, return the final wiggle subsequence length

Here's your problem of the day

Solving this problem will increase your chance to get selected in this company

Skill covered: Programming

What is recursion?

Choose another skill to practice
Similar interview experiences
Software Engineer
1 rounds | 1 problems
Interviewed by ConsultAdd Inc
52 views
0 comments
0 upvotes
Software Engineer
1 rounds | 2 problems
Interviewed by ConsultAdd Inc
48 views
0 comments
0 upvotes
Software Engineer
1 rounds | 1 problems
Interviewed by ConsultAdd Inc
46 views
0 comments
0 upvotes
Software Engineer
1 rounds | 2 problems
Interviewed by ConsultAdd Inc
52 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
Software Engineer
4 rounds | 1 problems
Interviewed by Newgen Software
3210 views
2 comments
0 upvotes
company logo
Software Engineer
3 rounds | 6 problems
Interviewed by HashedIn
2582 views
0 comments
0 upvotes
company logo
Software Engineer
2 rounds | 2 problems
Interviewed by Ernst & Young (EY)
0 views
0 comments
0 upvotes