0% found this document useful (0 votes)
37 views7 pages

Labview Core 1

The document outlines a series of programming challenges related to algorithms and data structures, including tasks such as finding missing and repeating numbers, peak detection, water trapping, Sudoku solving, and more. Each challenge provides specific requirements and examples to guide the implementation. The challenges are designed to test problem-solving skills in various scenarios, including game development and matrix manipulation.

Uploaded by

aeronauttrades
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views7 pages

Labview Core 1

The document outlines a series of programming challenges related to algorithms and data structures, including tasks such as finding missing and repeating numbers, peak detection, water trapping, Sudoku solving, and more. Each challenge provides specific requirements and examples to guide the implementation. The challenges are designed to test problem-solving skills in various scenarios, including game development and matrix manipulation.

Uploaded by

aeronauttrades
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

LabVIEW Core 1- Practice Problems

1. Identify the Missing and Repeating Number:


You are given an unsorted array of size `n` where the elements are within the range of `1` to `n`. In
this array, one number from the set `{1, 2, ..., n}` is missing, and another number appears twice. Your
task is to find the missing number and the repeating number. e.g.
- Input: `arr[] = {3, 1, 3, 4, 5, 7, 7}`
- Output:
• Missing = 2,6
• Repeating = 3
- Explanation: The number 2 is missing, and the number 3 appears twice.

You are to output two string arrays i.e. Missing String Array and Repeating String Array.

2. Peak Detector Challenge:


Your task is to create a peak detection algorithm that allows the user to configure the window size for
comparison. Below is an example of a figure with a window length of 6.

Before Peak Detector

After Peak Detector


3. Water Trapping Challenge:
Your task is to design an algorithm that effectively traps water between the walls of a solid container.
The container is represented as a series of vertical walls of varying heights. You must ensure that water
is trapped between the walls on both sides. Water cannot be trapped if there is no wall on either side
to contain it.
The diagram below shows the container before and after water trapping:
- Left: The initial state of the container with solid walls.
- Right: The state of the container after water has been trapped.
Hint: The blue cells represent water, and the gray cells represent the container walls.
The goal is to correctly calculate the amount of water that can be trapped given the heights of the walls.

4. Sudoku Solver:
Given a partially filled 9×9 2D array ‘grid [9][9]’, the goal is to assign digits (from 1 to 9) to the empty cells
so that every row, column, and sub grid of size 3×3 contains exactly one instance of the digits from 1 to
9.
5. Surrounded Regions:
You are given an `m x n` array called `board` containing the letters 'X' and 'O'. Your goal is to identify
and capture regions of 'O' that are surrounded by 'X'.
- Connection: Cells are connected if they are next to each other horizontally or vertically.
- Region: A region is made up of connected 'O' cells.
- Surround: A region is surrounded if it is entirely enclosed by 'X' cells, with none of the 'O' cells
touching the edge of the board.

To capture a surrounded region, change all 'O's in that region to 'X's in the`board`.

6. Word Search:
Given an `m x n` board of characters and a list of strings `words`, return all the words that can be
found on the board.
Each word must be formed by letters from sequentially adjacent cells, where adjacent cells are next to
each other either horizontally or vertically. A cell cannot be used more than once in forming a word.

Example:

a) Input: words = ["abcd"]


Output: []

b) Input: words = ["abd"]


Output: [abd]

7. Sliding Window Maximum:

You are given an array of integers numbers, there is a sliding window of size k which is moving from the
very left of the array to the very right. You can only see the k numbers in the window. Each time the
sliding window moves right by one position.
Return the max sliding window.

Example 1:

Input: nums = [1,3,-1,-3,5,3,6,7], k = 3

Output: [3,3,5,5,6,7]

Explanation:

Window position Max


[1 3 -1] -3 5 3 6 7 3
1 [3 -1 -3] 5 3 6 7 3
1 3 [-1 -3 5] 3 6 7 5
1 3 -1 [-3 5 3] 6 7 5
1 3 -1 -3 [5 3 6] 7 6
1 3 -1 -3 5 [3 6 7] 7

8. Spiral Matrix:

Given an m x n array, return all elements of the matrix in spiral order.

Example 1:

Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]

Output: [1,2,3,6,9,8,7,4,5]

Example 2:

Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]

Output: [1,2,3,4,8,12,11,10,9,5,6,7]
9. Game of Life:
According to Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton
devised by the British mathematician John Horton Conway in 1970."
The board is made up of an m x n grid of cells, where each cell has an initial state: live (represented by
a 1) or dead (represented by a 0).
Each cell interacts with its eight neighbors (horizontal, vertical, diagonal) using the following four rules
(taken from the above Wikipedia article):

1. Any live cell with fewer than two live neighbors dies as if caused by under-population.
2. Any live cell with two or three live neighbors lives on to the next generation.
3. Any live cell with more than three live neighbors dies, as if by over-population.
4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

The next state is created by applying the above rules simultaneously to every cell in the current state,
where births and deaths occur simultaneously. Given the current state of the m x n grid board,
return the next state.

Example 1:

Input: board = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]]


Output: [[0,0,0],[1,0,1],[0,1,1],[0,1,0]]

Example 2:

Input: board = [[1,1],[1,0]]


Output: [[1,1],[1,1]]
10. Frog Jump:
A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or
may not exist a stone. The frog can jump on a stone, but it must not jump into the water.
Given a list of stones positions (in units) in sorted ascending order, determine if the frog can cross the
river by landing on the last stone. Initially, the frog is on the first stone and assumes the first jump must
be 1 unit.
If the frog's last jump was k units, its next jump must be either k - 1, k, or k + 1 units. The frog can only
jump in the forward direction.

Example 1:
Input: stones = [0,1,3,5,6,8,12,17]
Output: true
Explanation: The frog can jump to the last stone by jumping 1 unit to the 2nd stone, then 2 units to the
3rd stone, then 2 units to the 4th stone, then 3 units to the 6th stone, 4 units to the 7th stone, and 5
units to the 8th stone.

Example 2:
Input: stones = [0,1,2,3,4,8,9,11]
Output: false
Explanation: There is no way to jump to the last stone as the gap between the 5th and 6th stone is too
large.

11. 132 Pattern:


Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j]
and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].
Return true if there is a 132 pattern in nums, otherwise, return false.
Example 1:
Input: nums = [1,2,3,4]
Output: false
Explanation: There is no 132 pattern in the sequence.

Example 2:
Input: nums = [3,1,4,2]
Output: true
Explanation: There is a 132 pattern in the sequence: [1, 4, 2].

Example 3:
Input: nums = [-1,3,2,0]
Output: true
Explanation: There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0].
12. Tic-Tac-Toe Game:

Your task is to develop a simple Tic-Tac-Toe game. The game should meet the following
requirements:

a. Board Setup: Create a 3x3 grid where two players, X and O, can take turns to mark their
chosen cells.
b. Player Turns: Players should alternate turns, starting with Player X. Each player can choose
an empty cell on the grid to place their mark.
c. Winning Condition: The game is won when a player successfully places three of their marks
in a row, column, or diagonal.
d. Draw Condition: The game ends in a draw if all cells are filled and no player has achieved
three in a row.
e. User Interface: Display the board after each move, showing the current state of the game.
f. Input Validation: Ensure that players can only choose valid, empty cells on their turn.
g. Game Reset: Provide an option to reset the game and play again after a win or draw.

Your goal is to implement this game so that it can be played interactively.

You might also like