Server Side Programming Articles - Page 1449 of 2650

strlen() php function giving the wrong length of unicode characters ?

AmitDiwan
Updated on 20-Nov-2020 05:30:04

511 Views

To get the correct length, use mb_strlen() for Unicode characters.The PHP code is as follows −Example Live DemoOutputThe string length with mb_strlen=9 The string length with strlen=10

PHP Why does this && not trigger as false?

AmitDiwan
Updated on 20-Nov-2020 05:27:49

102 Views

This is because if you use && both conditions must be true. If any one condition becomes false then the overall condition evaluates to false.The PHP code is as follows −Example Live Demo OutputThe above condition is true

Lonely Pixel I in C++

Arnab Chakraborty
Updated on 19-Nov-2020 10:17:47

237 Views

Suppose we have a picture consisting of black and white pixels, we have to find the number of black lonely pixels. Here the picture is represented by a 2D char array consisting of 'B' and 'W', for the black and white pixels respectively.A black lonely pixel is actually 'B' that located at a specific position where the same row and same column don't have any other black pixels.If the input is like −WWBWBWBWWOutput will be 3. Because all the three 'B's are black lonely pixels.To solve this, we will follow these steps −n := size of picturem := (if n ... Read More

Inorder Successor in BST II in C++

Arnab Chakraborty
Updated on 19-Nov-2020 10:15:29

399 Views

Suppose we have a node in a binary search tree, we have to find the in-order successor of that node in the BST. If there is no in-order successor, return null. As we know that the successor of a node is the node with the smallest key greater than value of node.We will have direct access to the node but not to the root of the tree. Here each node will have a reference to its parent node. Below is the definition for Node −class Node {    public int val;    public Node left;    public Node right;   ... Read More

The Maze II in C++

Arnab Chakraborty
Updated on 19-Nov-2020 10:13:27

557 Views

Suppose there is a ball in a maze with empty spaces and walls. Now the ball can go through empty paths by rolling any direction like up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.We have to start position of ball, the destination and the maze, we have to find the shortest distance for the ball to stop at the destination. Here the distance is actually defined by the number of empty cells, that are covered by the ball (Excluding start position, including starting position). ... Read More

The Maze in C++

Arnab Chakraborty
Updated on 19-Nov-2020 10:05:40

4K+ Views

Suppose there is a ball in a maze with empty spaces and walls. Now the ball can go through empty paths by rolling any direction like up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.We have to start position of ball, the destination and the maze, we have to check whether the ball could stop at the destination. The maze is represented by one 2D array. Here 1 indicates the wall and 0 indicates the empty space. The borders of the maze are all walls. ... Read More

Max Consecutive Ones II in C++

Arnab Chakraborty
Updated on 19-Nov-2020 10:00:51

1K+ Views

Suppose we have a binary array; we have to find the maximum number of consecutive 1s in this array if we can flip at most one 0.So, if the input is like [1, 0, 1, 1, 0], then the output will be 4 because if we flip the first zero will get the maximum number of consecutive 1s. After flipping, the maximum number of consecutive 1s is 4.To solve this, we will follow these steps −ret := 1, n := size of numsif not n is non-zero, then −return 0j := 0, zero := 0for initialize i := 0, when ... Read More

Find Permutation in C++

Arnab Chakraborty
Updated on 19-Nov-2020 09:58:36

370 Views

Suppose we have a secret signature consisting of character 'D' and 'I'. 'D' denotes the decreasing relationship between two numbers, 'I' denotes increasing relationship between two numbers. And the secret signature was constructed by a special integer array, which contains uniquely all the different number from 1 to n.For example, the secret signature "DI" can be constructed from an array like [2, 1, 3] or [3, 1, 2], but not be constructed using array like [3, 2, 4] or [2, 1, 3, 4], which are both illegal constructing special string that can't represent the "DI" secret signature.Now we have to ... Read More

Sequence Reconstruction in C++

Arnab Chakraborty
Updated on 19-Nov-2020 09:56:33

268 Views

Suppose we have to check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. The original sequence is a permutation of the integers from 1 to n, and n in range 1 ≤ n ≤ 10^4. Here the reconstruction means making a shortest common supersequence of the sequences in seqs. We have to check whether there is only one sequence that can be reconstructed from seqs and it is the original sequence.So, if the input is like org = [1, 2, 3], seqs = [[1, 2], [1, 3]], then the output will be false, because ... Read More

Design Phone Directory in C++

Arnab Chakraborty
Updated on 19-Nov-2020 09:52:43

610 Views

Suppose we want to design a Phone Directory which supports the following operations −get − This will provide a number that is not assigned to anyone.check − This will check whether a number is available or not.release − This will recycle or release a number.Using the initializer, we can initialize n numbers at firstTo solve this, we will follow these steps −Define one set sDefine one queue availableThe initializer will take maxNumbers.N := maxNumbersfor initialize i := 0, when i < N, update (increase i by 1), do −insert i into availableDefine a function get()if size of available is same ... Read More

Advertisements