Posts

Lonely Integer - Given an array of integers, where all elements but one occur twice, find the unique element. Hackerrank Solution

Given an array of integers, where all elements but one occur twice, find the unique element. Example a = [1, 2, 3, 4, 3, 2 ,2] The unique element is 4. Function Description Complete the lonelyinteger function in the editor below. lonelyinteger has the following parameter(s): ·        int a[n]: an array of integers Returns ·        int: the element that occurs only once Input Format The first line contains a single integer, n  , the number of integers in the array. The second line contains n  space-separated integers that describe the values in  a . Constraints ·        1 <= n < 100 ·        It is guaranteed that n is an odd number and that there is one unique element. ·        0 <= a[i] <= 100, where 0 <= i < n. In Java  import java.io.*; import j...

Diagonal Difference - HackerRank Solutions

  Given a square matrix, calculate the absolute difference between the sums of its diagonals. For example, the square matrix  is shown below: 1 2 3 4 5 6 9 8 9   The left-to-right diagonal 1 + 5 + 9 = 15. The right to left diagonal 3 + 5 + 9 = 17. Their absolute difference is 2. Function description Complete the diagonalDifference  function in the editor below. diagonalDifference takes the following parameter: int arr[n][m]: an array of integers Return int: the absolute diagonal difference Input Format The first line contains a single integer, , the number of rows and columns in the square matrix . Each of the next  lines describes a row, , and consists of  space-separated integers . Output Format Return the absolute difference between the sums of the matrix's two diagonals as a single integer. Sample Input 3 11 2 4 4 5 6 10 8 -12 Sample Output 15 Explanati...
  dot  product The  dot  tool returns the dot product of two arrays. import numpy A = numpy.array([ 1, 2 ]) B = numpy.array([ 3, 4 ]) print numpy.dot(A, B) #Output : 11 cross The  cross  tool returns the cross product of two arrays. import numpy A = numpy.array([ 1, 2 ]) B = numpy.array([ 3, 4 ]) print numpy.cross(A, B) #Output : -2 Task You are given two arrays   and  . Both have dimensions of  X . Your task is to compute their  matrix product . Input Format The first line contains the integer  . The next   lines contains   space separated integers of array  . The following   lines contains   space separated integers of array  . Output Format Print the matrix multiplication of   and  . Sample Input 2 1 2 3 4 1 2 3 4 Sample Output [[ 7 10] [15 22]] Solution import numpy n = int(input()) a = numpy.array([input().split() for _ in range(n)], int) b ...

Pagination in PHP

Image
  Calculate total pages Different records on each page Calculate offset $limit = 5; if(isset($_REQUEST['page'])){ $page = $_REQUEST['page']; }else{ $page = 1; } $offset = ($page - 1) * $limit;     <!-- Pagination Start --> <div class="w3-row pagination">   <?php     $sql2 = "SELECT pro_id FROM project_request pr     INNER JOIN student s ON pr.pro_stu_id = s.stu_id     WHERE pr.pro_review = ?";       $result2 = $conn->prepare($sql2);     $result2->execute(array(0));     $row2 = $result2->fetchAll(PDO::FETCH_ASSOC);     if($result2->rowCount()){       $total_records = $result2->rowCount();       $total_pages = ceil($total_records/$limit);       echo '<ul>';       if($page > 1){         echo '<li class="w3-button w3-grey mx-1...

Image update in PHP with updating of other fields - Update Image with other fields

    <form action="" method="POST" enctype="multipart/form-data">   <label for="name">Name</label>   <input type="text" class="w3-input w3-border" id="name" name="name" required value="<?php echo $row2['stu_name']; ?>">   <label for="email">Email</label>   <input type="email" class="w3-input w3-border" id="email" name="email" required value="<?php echo $row2['stu_email']; ?>" >  <label for="profilepic">Profile Picture <small> (Note : Image size should be less than 500 KB) </small></label>  <input type="hidden" name="old-image" value="<?php if(isset($img)){ echo $img; }  ?>">   <input type="file" class="w3-input w3-border w3-white" id="profilepic"...

File upload using JavaScript with validation (Apply validation on frontend side)

 JavaScript is a client side scripting language. With JavaScript we can easily validate our file with extension, file size.  input element object .files   <form action="" method="POST" enctype="multipart/form-data" id="form"> <label>Upload</label> <input class="w3-input w3-white" id="file" name="file" type="file" /> <input name="upload" type="hidden" value="" /> <button id="Upload" name="upload" type="submit">Upload</button> </form> <div id="embed"></div> <script>  document.getElementById('Upload').addEventListener('click', (e) => {    e.preventDefault();    if(document.getElementById('file').value){ // console.log(document.getElementById('file').files);  All property of file     var files = document.getElementById('file...

How to remove 000webhost watermark

  000webhost.com is a free web hosting service provider website. Which offer free and premium hosting services. 000webhost does not permit turn off banner powered by 000webhost with free account. There are some other method which will work. work. Paste this code in every page of your website or webpage. This will remove the Russia/Ukraine war watermark or banner from the footer of the webpage. Paste this code in the script tag at the end of the body element. document.addEventListener('DOMContentLoaded', () => { var disclaimer = document.querySelector("img[alt='www.000webhost.com']"); if(disclaimer){ disclaimer.remove(); } });