instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a TensorFlow 2.0 program that calculates the standard deviation of an array.
You are given an array of integers. The program should first calculate the mean of the array. Then, it should calculate the squared difference between each element in the array and the mean. Next, it should calculate the sum of all the... | codefeedback |
Can you write a function that returns the sum of the positive even elements of a given array, excluding any elements that are divisible by 3? The function should handle both positive and negative integers. Additionally, the function should also exclude any elements that are divisible by 2 and 5. | codefeedback |
Transform the given code into an array of objects in JavaScript, ensuring that each object contains properties for both name and age. Additionally, each name must be a string and each age must be a positive integer. However, you should also validate that the age is within a specific range, such as between 18 and 65. | codefeedback |
How can you reverse a given string using a while loop, without using any built-in string reversal functions? Additionally, you are not allowed to use any additional variables to store the reversed string. string = "hello" | codefeedback |
Create a JavaScript function which takes a string and returns the longest word in it, excluding any words that contain the letter "z". For example, given the string "This is an example string", the function should return "example". | codefeedback |
Create a function called check_restaurant_availability that returns True if a restaurant is open on a given day and False if it's closed. The function should take two parameters: a dictionary representing the restaurant's status for each day of the week and a string representing the day for which the availability shoul... | codefeedback |
How can you fill a 2D array with zeros using a single loop and without using any built-in functions or methods? Additionally, ensure that the array is a jagged array, where each inner array can have a different length. | codefeedback |
Generate 5 random prime numbers between 1000 and 10000, such that the sum of the digits of each prime number is a prime number itself. | codefeedback |
Select the last three unique elements from a given list, where the list contains at least 7 elements, and display them in descending order. If there are less than three unique elements, display all of them in descending order.
mylist = [1,2,3,4,5,5,6,7,8,8,9,10,10] | codefeedback |
Given a list of strings, how can you join them all together into a single sentence? The order of the strings in the sentence should follow a specific pattern: the first string should be in lowercase, the second string should be in uppercase, the third string should be in lowercase, and so on. Additionally, any strings ... | codefeedback |
Create a custom min-heap data structure in Python that supports the following operations:
1. Insertion: Insert an element into the heap while maintaining the min-heap property.
2. Deletion: Remove the minimum element from the heap while maintaining the min-heap property.
3. Peek: Return the minimum element in the heap ... | codefeedback |
Given an unsorted array of integers, sort it using the quick sort algorithm. The array will contain both positive and negative numbers. The output should be in ascending order. If there are duplicate numbers, they should be placed next to each other in the sorted array. Implement the quick sort algorithm from scratch w... | codefeedback |
## Updated Test
Given two strings s1 and s2, how can you check if s2 is a substring of s1?
Write a function `is_substring(s1: str, s2: str) -> bool` that returns True if s2 is a substring of s1 and False otherwise.
**Examples**
```
is_substring("testString", "String") => True
is_substring("testString", "ing") => True... | codefeedback |
Find the most frequent value in a list, but the list can also contain strings. Return the most frequent value as a string if it is a string, otherwise return it as an integer. The list can contain up to 1 million elements.
mylist = [1,2,3,4,4,4,4,5,5,'hello','hello','world', 'a'*1000000] | codefeedback |
Measure the execution time of a given python script and print the total number of iterations performed by the script within the given time limit. The script should use multithreading and ensure thread safety while performing the iterations. | codefeedback |
Explain the concept of method overriding in object-oriented programming and provide an example in Python. Describe the difference between method overriding and method overloading, and discuss when each technique is appropriate to use in a program. | codefeedback |
Given a dataset containing string and integer pairs, find all unique values and return them in descending order based on the frequency of occurrence. If two values have the same frequency, return them in ascending alphabetical order.
dataset = [['apple', 4], ['banana', 5], ['apple', 3], ['cherry', 2], ['banana', 5], [... | codefeedback |
Given the following Java code, can you spot the error and propose a solution to fix it?
public class MyClass {
int x = 10;
int y = 20;
public static int add(int x, int y) {
int sum = x + y;
return sum;
}
public static void main(String[] args) {
MyClass obj = new MyClass();
System.out.printl... | codefeedback |
Write a function in Javascript to return the k-th highest number in an array, where k is a parameter passed to the function. The function should also handle cases where k is larger than the size of the array. Additionally, the function should return an error if the array contains duplicate numbers.
Array: [1, 2, 3, 11... | codefeedback |
Define a function to calculate the product of three prime numbers, with the condition that all three prime numbers must be unique. | codefeedback |
Write a JavaScript program to group an array of objects based on a property and sum up the values of the grouped objects. Each object in the array will now also have a "department" property. Additionally, the program should only sum up the values of objects whose salary is above a certain threshold (specified as an add... | codefeedback |
How can we efficiently convert a sql query with complex joins and subqueries into pandas code, using only vectorized operations while also ensuring that the solution is optimized for large datasets? | codefeedback |
Write a program that takes in a sentence as input and prints out all the words that start with a vowel, while ignoring any words that contain the letter 'e'. | codefeedback |
Write a Python program that reads a CSV file and calculates the sum of the values in a specific column. The program should prompt the user to enter the name of the file and the column index. Use try-except statements to handle any errors that may occur during the file reading process, such as a FileNotFoundError or a V... | codefeedback |
Create a function that takes a string as input and prints each letter of the string on a separate line. Additionally, you should also print the index of each letter in the original string. However, the function should only print the letters that are in uppercase and their corresponding indices.
Example:
Input: "Hello... | codefeedback |
Compare two dictionaries for equality and return the result. The order of the key-value pairs should not affect the result. Both dictionaries can contain nested dictionaries as values. Additionally, the function should ignore any keys that start with an underscore (_).
a = {1:4, 2:{5:7, 6:8}, 3:6, 4:{7:9, 8:{9:10, 10:... | codefeedback |
Verify that the following web development code is correct and contains valid HTML syntax and proper structure, while also ensuring that the code adheres to specific accessibility guidelines.
<html>
<head>
<title>My first web page</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<heade... | codefeedback |
Convert the given if-else statement written in JavaScript to a ternary operator. Additionally, implement an error handling mechanism to display a custom error message if the input value of x is not a number and ensure that x is between 1 and 100. | codefeedback |
Explain how a stack data structure is implemented in a programming language of your choice. Provide an example code snippet demonstrating the push and pop operations, along with an explanation of how these operations are typically used in memory management. | codefeedback |
Write a query in SQL to find the names, age, and salary of all employees that work in the IT department and have a salary greater than $50,000. Additionally, calculate the bonus for each employee based on their salary. The bonus should be 10% of the salary if the salary is less than or equal to $100,000, and 15% of the... | codefeedback |
Find the median of this sequence of numbers: 4, 3, 7, 10, 9, 6, 2, 1, 8, 5. Additionally, implement a solution that does not use any built-in sorting functions or data structures. | codefeedback |
Given a triangle with any angles and side lengths, write a function to compute its area using the Law of Cosines. Your function should also check if the triangle is valid, meaning that the sum of any two sides must be greater than the third side. If the triangle is not valid, the function should return an error message... | codefeedback |
How would you create a function in JavaScript that returns a string that contains the word "Hello" 5 times, without using any loop or built-in string manipulation methods, and each repetition of "Hello" should be in a different language (e.g. English, French, Spanish, German, and Japanese)? | codefeedback |
Write a JavaScript function that returns the current date and time in the format "Wednesday, November 20, 2019 10:30 AM". The function should also include the day of the week, the month name, and the 12-hour time format with AM/PM indicators.
Additionally, the function should include error handling to handle cases whe... | codefeedback |
Write a Python program that prints all prime numbers from 1 to 100. Additionally, you should also print a message for each number stating whether it is a prime number or not.
#Solution#
import math
def is_prime(num):
if num <= 1:
return False
for i in range(2, int(math.sqrt(num)) + 1):
if num... | codefeedback |
Write Python code to extend a string to be five times as long as the original string. The string should be repeated five times, with a special character of your choice between each repetition. The extended string should have the original string at the center, surrounded by two copies of the original string in reverse o... | codefeedback |
Rewritten Test:
What type of function does the following code represent? What is the time complexity of this function?
function foo(x, y) {
let result = 0;
for (let i = 0; i < x; i++) {
for (let j = 0; j < y; j++) {
result += (i + j);
}
}
return result;
}
Explanation:
The original code simply ... | codefeedback |
Create a function in Python that will take two parameters: a string and an integer, and return the string repeated the amount of times specified by the integer. The function should have a time complexity of O(n), where n is the length of the string, and a space complexity of O(1).
Additionally, the function should han... | codefeedback |
Write a Java code snippet to print the following line of text: “Hello, World!” but ensure that the word "World" is printed in reverse order and all the letters are capitalized. | codefeedback |
Using the given code, implement the function "add_two_numbers" which will take two integers, both ranging from -1000 to 1000, and return their sum. You are not allowed to use the "+" operator or any built-in functions for addition. Instead, you should implement addition using only bitwise operators and a maximum of 10 ... | codefeedback |
Compose a JavaScript code to sum all odd numbers in the range from 1 to 1000000.
#Additional reasoning steps#
1. Start by initializing a variable "sum" to 0 to keep track of the sum of odd numbers.
2. Use a for loop to iterate through all numbers from 1 to 1000000.
3. Inside the loop, use an if statement to check if t... | codefeedback |
Design a text-based game in C++ in which the player can move around a procedurally generated game world and interact with objects and characters. Implement a feature that allows the player to engage in turn-based combat with enemies, where the player can use a variety of skills and abilities to defeat them. Each enemy ... | codefeedback |
Write a code to delete the element at a given index in a two-dimensional array, while also shifting all the elements in the same row and column as the deleted element to fill the gap. The array will be represented as a list of lists.
Example array: [[4, 5, 6], [7, 8, 9], [10, 11, 12]]
Index: (1, 1) | codefeedback |
Create a custom encryption algorithm to encode a string of characters. The encryption algorithm should not rely on any built-in encryption functions or libraries. Additionally, the algorithm should include a decryption function to decode the encoded string back to its original form.
The encryption algorithm should us... | codefeedback |
Explain what is the value of the variable x after this following code is executed, assuming that the value of x must be between 0 and 100 (inclusive):
x = 5
y = x * 2 + 9 + x/3 - x%2 - 5**2 + (7 - 2*3) | codefeedback |
Write a JavaScript function that takes in an array of numbers as a parameter and prints only the prime numbers in ascending order. The function should ignore any non-numeric values in the array. Additionally, the function should return the sum of all prime numbers in the array.
Note: A prime number is a natural number... | codefeedback |
Write a Bash shell script that accepts an optional flag `-r` as the first argument, followed by any number of filenames as the subsequent arguments. The script should print the filenames in reverse order if the `-r` flag is provided, and in regular order if the flag is not provided. Additionally, the script should disp... | codefeedback |
Create a JSON object with the following data: five fruits of each color {red: [apple, watermelon, strawberry, cherry, raspberry], green: [apple, kiwi, honeydew, lime, avocado], yellow: [banana, lemon, mango, pineapple, peach]}. Additionally, the JSON object should include the number of seeds in each fruit and the avera... | codefeedback |
Write code to count how many times a specific substring appears in a given string, while also ignoring any occurrences of the substring within another substring. Additionally, the code should be case-sensitive.
String: "banana"
Substring: "na"
For example, in the given string "banana", the substring "na" appears twic... | codefeedback |
Write a Python function that finds and returns the number of occurrences of a particular character in a string. Additionally, handle the case where the input string is None and raise a ValueError exception. The function should also ignore any occurrences of the character within quotes or parentheses in the string. | codefeedback |
Compute the Damerau-Levenshtein distance between two provided words.
word1 = "cat"
word2 = "bat" | codefeedback |
Create an efficient sorting algorithm to sort an array of integers in ascending order. The algorithm should have a time complexity of O(nlogn) and should not use any built-in sorting functions or libraries. Additionally, the algorithm should not use recursion and should not use any additional data structures (e.g., que... | codefeedback |
Write a Java method that takes in a string and returns an array containing all the possible permutations of this string. Additionally, each permutation should only contain unique characters. The time complexity of the algorithm should be less than O(n!), where n is the length of the string. | codefeedback |
Write a JavaScript function that reverses a given array without using the built-in reverse() method. The function should also handle arrays that contain nested arrays or objects as elements. The function should have a time complexity of O(n^2), where n is the length of the input array.
For example, given the following... | codefeedback |
Implement a web scraping algorithm to gather detailed information about a given product from an e-commerce website, including the product's name, price, description, customer reviews, and specifications. The algorithm should be capable of handling websites with dynamic content loaded via AJAX requests. The time complex... | codefeedback |
Implement a python class named 'Temperature' that ranks a temperature value as cold, warm, or hot given a threshold value of 30. The class should also keep track of the number of times the temperature has been checked and provide a method to reset the count. Additionally, the class should have a method that returns the... | codefeedback |
Write a JavaScript function that takes a string and an array of strings. Return an array with elements from the string filtered by the array of strings provided. The function should have a time complexity of O(n^2), where n is the length of the string. | codefeedback |
Write a Python script to create a web server that can respond to "GET" and "POST" requests from a web browser. Additionally, the script should be able to handle multiple concurrent connections using threading or multiprocessing.
The server should also support persistent connections, where the client can send multiple... | codefeedback |
Write a C# method that takes in a decimal number and multiplies it by the sum of its digits. Additionally, the method should also calculate the product of the sum of the digits and the factorial of the number of digits in the decimal number. | codefeedback |
Implement a JavaScript ES6 class 'Rectangle' that has the following properties and methods:
Properties:
- length: a number representing the length of the rectangle
- breadth: a number representing the breadth of the rectangle
Methods:
- getArea: a method that returns the area of the rectangle (length * breadth)
- get... | codefeedback |
Create a CSS stylesheet that colors the background of a webpage with a random shade of blue whenever the page is refreshed. Additionally, the shade of blue should be randomly generated by taking into account the values of the red, green, and blue color channels, ensuring that the resulting color is visually appealing a... | codefeedback |
Create a program in Python that searches for a specific word in a string and counts the number of times the word appears. However, the program should also consider variations of the word such as uppercase and lowercase letters and return both the count and the positions of all occurrences of the word, regardless of cas... | codefeedback |
Create a program in Java to reverse a sentence while maintaining the order of the words and removing any duplicate words.
For example, if the input sentence is "This is a sample sentence is a," the output should be "a is sentence sample This."
Provide a piece of erroneous code to mislead the candidates:
```
String[] wo... | codefeedback |
Create a function in Java that changes a given string to uppercase, but without using the built-in `toUpperCase()` function or any additional data structures. The function should have a time complexity of O(n), where n is the length of the input string.
The function should also handle non-alphabetic characters in the... | codefeedback |
Write a C++ function that takes in a linked list and a value, and inserts the value as the head node of the list. The linked list is represented using a struct with a data field and a next field, where next points to the next node in the list or nullptr if it is the last node.
The function should handle the following ... | codefeedback |
Create a single-page application (SPA) using React that includes a navigation bar with links to three separate components. Each component should contain a form with input fields for name and email, and a submit button. When the submit button is clicked, the form data should be validated to ensure that the name and emai... | codefeedback |
Write a code to traverse a given binary tree in a zigzag pattern using an iterative method. | codefeedback |
Create a function that accepts two parameters, a string and a list of strings, and returns a dictionary where the keys are the unique strings in the list and the values are the number of occurrences of each string. | codefeedback |
Write a function that takes a string and a key as parameters and encrypts the string using the following steps:
1. Convert the key into a numeric value. Each character in the key should be mapped to its corresponding ASCII value and summed up. The key should contain at least 3 characters.
2. Iterate over each character... | codefeedback |
Process the curl request and output a JSON from it. The curl request should include a custom header "Authorization: Bearer <access_token>". The JSON response should include the user's name, email, and a list of their recent activities. The API endpoint is 'https://api.example.com/user/12'. Additionally, handle any poss... | codefeedback |
Create a MySQL table with a primary key and three other columns. The primary key column should auto-increment and have a minimum value of 100. The first additional column should only accept unique values, cannot be NULL, and must have a default value of the current timestamp. The second additional column should be of t... | codefeedback |
Translate the following sentence into its Python equivalent. The input will always be a list of integers. For each number, if it is divisible by both 3 and 7, print 'FizzWoof'; if it is divisible by 3, print 'Fizz'; if it is divisible by 7, print 'Woof'; otherwise, print the number itself. | codefeedback |
Rewritten Test:
Explain the concept of variable scoping in programming languages and compare the differences between static, automatic, dynamic, and global variables. Discuss the potential drawbacks and benefits of using global variables in a software project. Additionally, provide an example scenario where the use of ... | codefeedback |
Increase the difficulty by proposing a solution that requires the time complexity of O(n log n) and the space complexity of O(1).
Write a function that takes in a list of integers and rearranges them in ascending order. The function should then divide the list into sublists where each sublist contains consecutive inte... | codefeedback |
Modify the following code snippet to print the total number of lowercase characters in the string. The program should also exclude any lowercase characters that are immediately preceded or followed by an uppercase character.
string = 'Hello World!'
#Erroneous code reference#
string = 'Hello World!'
total = 0
for cha... | codefeedback |
Describe how higher-order functions can be used to implement a functional programming paradigm in a specific programming language of your choice, and provide a code example demonstrating the usage of higher-order functions in a real-world scenario. | codefeedback |
What are the common types of syntax errors in programming and how can they be fixed? In your solution, you must implement a custom error handling mechanism to handle these syntax errors and provide meaningful error messages to the user. | codefeedback |
Explain function overloading in C++ and provide two examples to illustrate its usage. In the first example, create a class called "Calculator" with two member functions named "add" and "add" with the same name but different parameter types. The "add" function with two integer parameters should return the sum of the int... | codefeedback |
Write a program to find the minimum spanning tree of a connected, weighted, undirected graph. The program should also handle graphs with negative weights and output an error message if a negative cycle is detected. | codefeedback |
Implement an iterative solution to calculate the nth Fibonacci number using constant space complexity.
In addition, optimize the time complexity of your solution to O(log n) by using matrix exponentiation. | codefeedback |
Generate a CSS selector to apply the following style attributes to all <p> tags that are direct children of a <div> element with the class "content", and are not nested within any other elements. Additionally, the CSS selector should exclude any <p> tags that have the class "excluded" or are located within a <div> elem... | codefeedback |
Write a code to return the key of the maximum element in a dictionary. However, you are not allowed to use the built-in max() function or any other sorting functions. | codefeedback |
What would be the result of running the following SQL query?
Consider the following database schema:
Table: products
Columns: id (integer), name (varchar), price (decimal), category (varchar)
Write an SQL query that retrieves all the columns from the products table where the price is less than 10 and the category is... | codefeedback |
Debug the following code so it can print the corresponding JSON data correctly. Additionally, modify the code to handle the case when the "profession" key is missing in the JSON string. Implement error handling to display an appropriate message when the JSON string is empty or invalid. | codefeedback |
Write a Python function to find the largest prime factor of a given integer. The function should include error handling for invalid input, such as non-integer values or negative numbers. Additionally, the function should implement the Pollard's rho algorithm for finding prime factors, which uses Brent's cycle detection... | codefeedback |
Write a Python script that takes a list of integers as input and returns the largest and smallest numbers in the list. The script should meet the following requirements:
1. The script should run in O(n) time complexity, where n is the size of the input list.
2. The script should not use any built-in functions or libra... | codefeedback |
Write a code to open a webpage in your default web browser and retrieve the HTML content of the webpage.
URL: https://example.com/
Additionally, parse the HTML content and extract all the hyperlinks present on the webpage.
Furthermore, filter out any duplicate hyperlinks and sort them in alphabetical order.
Finally,... | codefeedback |
What HTML element is used to create a table with a specific number of rows and columns, where each cell contains a specific value, and each row has a different background color? | codefeedback |
Write a code to print the first 100 prime numbers in reverse order. | codefeedback |
Explain the difference between a local and a global variable in Python and provide an example of when each type would be most appropriate to use. Additionally, describe the concept of variable scoping in Python and how it affects the accessibility of variables within different code blocks. | codefeedback |
Compare and contrast the main components of an object-oriented programming language and a procedural programming language. Discuss the advantages and disadvantages of each approach and provide examples to support your explanation. | codefeedback |
Write a SQL query to delete all customers who have not made any purchases in the past 6 months, and also delete any related records in other tables that are dependent on the customer's ID.
Note: The schema includes the following tables:
- Customers: (customer_id, name, email, phone)
- Purchases: (purchase_id, custome... | codefeedback |
Describe a greedy algorithm for the knapsack problem with fractional values, where each item has a weight and a value, and the total weight of items in the knapsack cannot exceed a given capacity. Additionally, each item now has a limited quantity, and you can only take a maximum of k items of each type. The goal is to... | codefeedback |
Create a new list 'squared' that contains the squares of all the elements in the list 'nums'. However, you are not allowed to use any built-in functions or operators for exponentiation (such as `**` or `pow()`). The input list 'nums' can contain both positive and negative integers.
Example:
Input: nums = [1, 2, 3, 4, ... | codefeedback |
Suggest an algorithm to determine whether a string is a palindrome. Your solution should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Given a string consisting of uppercase and lowercase alphabets, numbers, and special characters, find the length of the string. The length should be calculated without using any built-in functions or libraries that directly give the length of a string. Additionally, the solution should not use any loops or recursion. T... | codefeedback |
What are the benefits and drawbacks of using multithreading in an application, considering both performance and resource utilization? Provide an example of how multithreading can introduce synchronization and deadlock issues, and explain how they can be resolved using locks and condition variables. | codefeedback |
Using Java, write a function that takes an input string and returns the string reversed, but with all punctuation marks removed. The function should also convert all letters to lowercase and remove any duplicate characters. | codefeedback |
Create a Python class "Book" with name, price, and quantity properties. Implement a method "apply_discount" that takes a percentage discount as a parameter and updates the price property accordingly. The quantity property should also be updated based on the discount applied. Additionally, create a method "check_availab... | codefeedback |
Design a function that takes in a list of integers and returns the maximum sum that can be obtained by adding a subarray of the given list. A subarray is defined as a contiguous section of the original list.
The function should have a time complexity of O(n), where n is the length of the input list.
Provide a step-by... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.